# Clean up dataframe to keep only meaningful vars and drop NA, ready for LM
tidy_df <- function(src_df, ct, f, drop_islands=TRUE) {
  clean_bei_df <- src_df %>%
    select(CT_UID, all_of(all.vars(f))) %>%
    drop_na() %>%
    units::drop_units()
  
  # Join geom from CT dataframe
  df <- ct %>%
    transmute(CT_UID = GeoUID) %>%
    inner_join(clean_bei_df, by="CT_UID")
  
  # Build neighborhood (with islands) and extract island IDs
  ct_nb <- poly2nb(df)
  
  if (drop_islands) {
    islands <- lapply(ct_nb, min) %>% lapply(function(e) e == 0) %>% unlist %>% which()

    # Cleanup subset DF to drop islands and NA
    df <- df %>%
      filter(!row_number() %in% islands) %>%
      mutate(ct_no = row_number()) # Add CT number, matching row number
  
    # Recompute neighborhood
    ct_nb <- poly2nb(df)
    
    # Clean up final dataframe (no island, no NA's, pure dataframe)
    clean_df <- df %>%
      as.data.frame() %>%
      select(CT_UID, ct_no, all_of(all.vars(f)))
  }

  nbw = nb2listw(ct_nb, zero.policy = !drop_islands)
  nbmatx = nb2mat(ct_nb, style = "B", zero.policy = !drop_islands)
  
  list(df=clean_df, nbmatx=nbmatx, nbw=nbw, island_dropped=drop_islands)
}

This document builds on BEI_equity_paper.Rmd doc, which started as an analysis for the equity paper and moved to an exploration of the best modeling framework (simple OLS, spatial auto-regressive linear regression, spatial random effect model and INLA) to assess the relation between interventions and equity metrics. The conclusions of this exploration led to the following decisions:

  1. go with quintiles instead of absolute numbers (easier to interpret)
  2. use [zero inflated] Poisson distribution where fit (ie Bike lane ratio)
  3. use spaMM package to model association; INLA could be the focus of another methodological paper which would compare both approaches
  4. use non-buffered dependent variable, as spatial dependency is already taken care of through the spatial random effect

This document contains the analyses to be included in the BEI and equity paper.

1 Proposal

1.1 Original grant proposal for Census tract level analyses

1.1.1 Objective 1: Socio-spatial inequalities in urban interventions:

  • To test if urban interventions tend to be located in low SES neighborhoods (H1a); we will run the following model: \[Log(𝔼(UI_{𝑖} \mid X_{𝑖})) = \alpha + \beta_{1} * SES_{𝑖}\] a Poisson regression model with \(UI\) = the number of Urban Interventions between 2016 and 2021, \(SES\) = the socio-economic status of the census track at 2016.
  • To test the reduction in socio-economic inequalities in urban conditions (e.g. length and type of bicycle lanes, NDVI) between 2006 and 2020 (H1b), we will run the following model: \[𝔼(UC_{ij} \mid X_{ij}) = \beta_{0j} + \beta_{1j} ∗ SES + \beta_{2j} ∗ Time + \beta_{3j} ∗ SES ∗ Time + \epsilon_{ij}\] a multilevel linear model with \(UC\) = the Urban condition, \(SES\) = the socio-economic status of the census track.

1.1.2 Objective 2: Examining causal pathways and directionality of intervention/gentrification relation:

  • To test if urban interventions occur before gentrification or if gentrification occurs before the implementation of new urban interventions, we will run two models : (1) \[Logit(𝔼(G_{i} \mid X_{i})) = \alpha + \beta_{1} ∗ UI_{i} + + \beta_{2} ∗ PG_{i} + \beta ∗ X_{control_{i}}\] a logistic regression model among low SES census tracts (2006) with \(G\) = Gentrification between 2006 and 2016, \(UI\) = the number of Urban Interventions between 2001 and 2006, and \(PG\) = SES status 2006; and (2) \[Logit(𝔼(UI_{i} \mid X_{i})) = \alpha + \beta_{1} ∗ G_{i} + \beta_{2} ∗ UC_{i} + \beta ∗ X_{control_{i}}\] a Poisson regression model, with \(UI\) = the number of Urban Interventions between 2016 and 2023, \(G\) = Gentrification between 2006 and 2016, and \(UC\) = Urban Conditions in 2016.

1.2 Paper objective

We focus on obj #1: are urban interventions tend to be located in low SES neighborhoods. Here, the urban interventions considered are bike lanes and canopy/tree coverage and low SES ~ high Pampalon deprivation index. In a second step, we will look at the variations of UI and SES and their association.

Data extraction and pre-analyses for the paper looking at BEI and equity. BEI comprise bike lanes and canopy changes while equity is measured through Pampalon deprivation index. (Partially adapted from original work on BEI bike lanes – see bike_lane_stats.R and ReadMe.md.)

Paper is available here.

General processing steps:

  • Get CT 2016 boundaries (from Cancensus API)
  • Get BEI interventions (canopy / bike lanes) for the selected years (2011 / 2015 / 2016 / 2019)
  • Compute changes between years
    • for the original CT boundaries
    • for buffered CTs (250 / 500 / 750m)

In a second phase, these BEI changes will be linked to Pampalon index for 2016 (and 2011 ?)

1.3 Revision history

UPDATE 2021-12-02 Following discussion with @Yan, add normalized bike line changes:

  • by CT/buffer area
  • by street length within CT/buffer

UPDATE 2021-12-08 Following discussion with @Yan

  • Keep only normalized variation of bike lane length
  • Reverse relation: BEI metric = f(Equity metric (Pampalon / gentrification))
  • Display association at baseline, then add delta over time
  • Canopy : distinguish between high and low canopy

UPDATE 2022-01-14 Following discussion with @Ruben and @Yan

  • Test model with UC 2011 when modeling UI
  • Models with random slope probably not pertinent (see model 6, section 7.1.6)
  • Try to define Year variable as continuous instead of category in LME
  • Check if range of wSCOREMAT matches theoretical range of x-axis in graph (-.2 >> .2), might ponder the magnitude of the observed trend
  • Test three-way interaction instead of 2 times two-way interactions (interactions might be complicated to interpret…)
  • For gentrification and multilevel model, use GEE (logit)

UPDATE 2022-02-10 Following gentrification meeting

  • Add correlation matrix of SES variables (Caislin)
  • Drop wSCORESOC, which does not capture equity dimension (Meghan) [replaced by visible minority]
  • Paper focus should be on gentrification

UPDATE 2022-02-15

  • Add spatial autocorrelation test (Moran’s I)
  • Add Lagrange Multipliers to test best spatial model
  • Add comparison of OLS/SAR/SEM models

2 Built Environment Intervention Extraction

2.1 Bike lane changes

We use data categorized by Philippe Apparicio’s team who manually identified bike lanes for each census year since 1991. For this study, we limit ourselves to 2016, 2011 and 2006 census years.

On top of the original CT boundaries, three levels of buffer have been applied to the CT – 250m, 500m & 750m. Then the same series of processing steps (see above) have been applied to the buffers.

# Bike lanes, from Ph. Apparicio
reseau <- st_read(dsn="data/ReseauCyclableFinal.gdb", layer = "Reseau") # Already in NAD83 / MTM zone 8
## Reading layer `Reseau' from data source 
##   `/Users/benoit/WORKSPACE/gentrification_BEI_equity/data/ReseauCyclableFinal.gdb' 
##   using driver `OpenFileGDB'
## Simple feature collection with 82166 features and 72 fields
## Geometry type: GEOMETRY
## Dimension:     XYZ, XYZM
## Bounding box:  xmin: 266985.5 ymin: 5029251 xmax: 320986.1 ymax: 5062652
## z_range:       zmin: 0 zmax: 43
## m_range:       mmin: 0 mmax: 43
## Projected CRS: NAD83 / MTM zone 8
bike_lane <- reseau %>%
  filter(An2016 == 1 | An2011 == 1) %>%
  select(IdRte, ClsRte, Zone, starts_with("An"), starts_with("Typo_")) %>%
  st_cast("MULTILINESTRING") # Get rid of a few MULTICURVE geometries

# CT boundaries for Montreal
CT16 <- get_census(dataset='CA16', regions=list(CMA='24462'), level='CT', geo_format = "sf") %>%
  filter(Type == "CT") %>%
  mutate(interact_aoi = CD_UID %in% c(2466, 2465, 2458)) %>% # Flag Montréal island, Laval and the South shore (Longueuil, St-Lambert, Brossard)
  st_transform(st_crs(bike_lane))
## Reading geo data from local cache.
CT11 <- get_census(dataset='CA11', regions=list(CMA='24462'), level='CT', geo_format = "sf") %>%
  filter(Type == "CT") %>%
  st_transform(st_crs(bike_lane))
## Reading geo data from local cache.
compute_bikelane_by_area <- function(sf_areas, year_fld, typo_fld) {
  # Compute length of bike lanes within each area.
  # --
  # Parameters:
  #   - sf_areas: sf class object defining the areas of interest, must have a GeoUID field
  #   - year_fld: field name specifying the year of interest, e.g. An2016
  #   - typo_fld: field name specifying the typology for the year of interest, e.g. Typo_2016
  
  year_fld <- enquo(year_fld)
  typo_fld <- enquo(typo_fld)
  
  # Compute intersection of bike lanes with areas
  bk <- bike_lane %>%
    filter(!!year_fld == 1) %>%
    st_intersection(sf_areas) %>%
    mutate(bike_lane_length = st_length(.)) %>%
    as.data.frame() %>%
    group_by(GeoUID, !!typo_fld) %>%
    summarise(bike_lane_length = sum(bike_lane_length)) %>%
    ungroup() %>%
    pivot_wider(names_from = !!typo_fld, names_prefix = "Bike_class", names_sort = TRUE,
                values_from = bike_lane_length, values_fill = units::set_units(0, m)) %>%
    mutate(Bike_lane_total = units::set_units(rowSums(select(., starts_with("Bike_class"))), m))
  
  # Merge back into original sf_areas
  bk <- sf_areas %>%
    left_join(bk)
  
  # Replace NA by 0, which occur in Bike_class length
  bk[is.na(bk)] <- 0
  
  return(bk)
}

compute_streetlength_by_area <- function(sf_areas) {
  # Compute length of streets within each area.
  # --
  # Parameters:
  #   - sf_areas: sf class object defining the areas of interest, must have a GeoUID field

  # Compute intersection of streets with areas
  bk <- reseau  %>%
    st_cast("MULTILINESTRING") %>% # Get rid of a few MULTICURVE geometries
    st_intersection(sf_areas) %>%
    mutate(street_length = st_length(.)) %>%
    as.data.frame() %>%
    group_by(GeoUID) %>%
    summarise(street_length = sum(street_length)) %>%
    ungroup()
  
  # Merge back into original sf_areas
  bk <- sf_areas %>%
    mutate(shape_area_km2 = units::set_units(st_area(.), 'km^2')) %>%
    left_join(bk)
  
  # Replace NA by 0
  bk[is.na(bk)] <- 0
  
  return(bk)
}


# Compute year 2016 and year 2011 bike lanes within 2016 CTs
# NB: contrary to the original work, we keep the same area of reference, i.e. 2016
bike_lane_by_CT16 <- compute_bikelane_by_area(CT16, An2016, Typo_2016)
bike_lane_by_CT11 <- compute_bikelane_by_area(CT16, An2011, Typo_2011)
bike_lane_by_CT06 <- compute_bikelane_by_area(CT16, An2006, Typo_2006)

# Compute total street length within CT/buffer
street_length_by_CT16 <- compute_streetlength_by_area(CT16)

# Reorganize data to have all data in one dataframe
bike_lane_changes <- CT16 %>%
  left_join(select(as.data.frame(street_length_by_CT16), GeoUID, street_length, shape_area_km2), by="GeoUID") %>%
  left_join(select(as.data.frame(bike_lane_by_CT16), GeoUID, starts_with("Bike_")), by="GeoUID") %>%
  left_join(select(as.data.frame(bike_lane_by_CT11), GeoUID, starts_with("Bike_")), by="GeoUID", suffix=c(".2016ct", ".2011ct")) %>%
  left_join(select(as.data.frame(bike_lane_by_CT06), GeoUID, starts_with("Bike_")), by="GeoUID")

# Compute ratio of bike lane vs street length
bike_lane_changes <- bike_lane_changes %>%
  transmute(GeoUID = GeoUID,
            interact_aoi = interact_aoi,
            street_length = street_length,
            street_length.hm = street_length / 100, # in hectometers
            Bike_lane_total.2016ct = Bike_lane_total.2016ct,
            Bike_lane_total.2011ct = Bike_lane_total.2011ct,
            Bike_lane_total.2006ct = Bike_lane_total,
            Bike_lane_total.hm.2016ct = as.integer(round(Bike_lane_total.2016ct/100)),
            Bike_lane_total.hm.2011ct = as.integer(round(Bike_lane_total.2011ct/100)),
            Bike_lane_total.hm.2006ct = as.integer(round(Bike_lane_total/100)),
            Bike_lane.by.street.2016ct = 100 * Bike_lane_total.2016ct / street_length,
            Bike_lane.by.street.2011ct = 100 * Bike_lane_total.2011ct / street_length,
            Bike_lane.by.street.2006ct = 100 * Bike_lane_total / street_length)

# Compute change between 2011 and 2016 (only for total bike lane length)
bike_lane_changes <- bike_lane_changes %>%
  mutate(Bike_lane_diff.2011.2016ct = Bike_lane_total.2016ct - Bike_lane_total.2011ct)

# Normalize bike lane change by (i) street length and (ii) area
bike_lane_changes <- bike_lane_changes %>%
  mutate(Bike_lane_diff.by.street.2011.2016ct = 100 * Bike_lane_diff.2011.2016ct / street_length)

# Save results
st_write(bike_lane_changes, dsn = "data/bike_length_changes.gpkg", delete_layer = TRUE)
## Deleting layer `bike_length_changes' using driver `GPKG'
## Writing layer `bike_length_changes' to data source 
##   `data/bike_length_changes.gpkg' using driver `GPKG'
## Writing 970 features with 15 fields and geometry type Multi Polygon.
# Clean up
rm(buf_CT16)
rm(bike_lane_by_CT11, bike_lane_by_CT16, bike_lane_by_CT06)
rm(street_length_by_CT16)

2.1.1 Illustration of bike lane metrics

Check output for one specific dataset (Census tracts 2016, no buffer)

2.1.1.1 Raw length

Bike lane length in 2016 within CTs, measured in meters

ggplot() +
   geom_sf(data=filter(bike_lane_changes, interact_aoi), mapping = aes(fill=as.numeric(Bike_lane_total.2016ct)), lwd=0) +
  scale_fill_continuous(name = "Total length (m)")+ 
  labs(title = "Length of bike lanes within 2016 CTs")

2.1.1.2 Absolute length change

Absolute bike lane length change between 2011 and 2016, in meters

ggplot() +
   geom_sf(data=filter(bike_lane_changes, interact_aoi), mapping = aes(fill=as.numeric(Bike_lane_diff.2011.2016ct)), lwd=0) +
  scale_fill_gradient2(name = "Length (m)")+ 
  labs(title = "Changes in bike lane between 2011 and 2016")

2.1.1.3 Normalized length change (by street)

Relative bike lane length change between 2011 and 2016, normalized by street length within CT in 2016, expressed in %

\[Variation = \frac{Bike Lane_{2016}}{Street Length_{2016}} - \frac{Bike Lane_{2011}}{Street Length_{2016}}\]

ggplot() +
   geom_sf(data=filter(bike_lane_changes, interact_aoi), mapping = aes(fill=as.numeric(Bike_lane_diff.by.street.2011.2016ct)), lwd=0) +
  scale_fill_gradient2(name = "Variation (%)")+ 
  labs(title = "Changes in bike lane between 2011 and 2016, normalized by street")

2.1.2 Basic stats on each layer

At the Census Tract level.

# CT level
ggplot(bike_lane_changes) +
  geom_histogram(aes(as.numeric(Bike_lane_diff.2011.2016ct)), binwidth = 250) + 
  xlab("Difference of bike lane length between 2016 and 2011 | CT level")

summary(bike_lane_changes$Bike_lane_diff.2011.2016ct)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -1377.7     0.0     0.0   262.1   189.7 14463.8
ggplot(bike_lane_changes) +
  geom_histogram(aes(as.numeric(Bike_lane_diff.by.street.2011.2016ct))) + 
  xlab("Difference of bike lane length between 2016 and 2011, normalized by street")

summary(bike_lane_changes$Bike_lane_diff.by.street.2011.2016ct)
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max.     NA's 
## -100.000    0.000    0.000    3.665    4.496  100.000      252

2.2 Canopy changes

Canopy changes is based on data produced by CMM, using multispectral aerial imagery and lidar. In order to sync the observations with the census years, we focus on 2011 and 2019 with one extra observation point in 2015.

The processing steps are similar to the ones for the bike lanes:

  • Import the raster for each of the 3 years
  • Compute proportion of canopy within each CT for the 3 years
# Codes du raster "espace vert"
# 0. No data (hors CMM)
# 1. NDVI < 0,3 et MNH < 3,0m = Minéral bas (route, stationnement, etc.)
# 2. NDVI < 0,3 et MNH ≥ 3,0m = Minéral haut (constructions)
# 3. NDVI ≥ 0,3 et MNH < 3,0m = Végétal bas (culture, gazon, etc.)
# 4. NDVI ≥ 0,3 et MNH ≥ 3,0m = Végétal haut (canopée)
# 5. Aquatique

# Load rasters into pg database for further processing
system('psql -d gentrif_bei -c "CREATE EXTENSION IF NOT EXISTS postgis"')
system('psql -d gentrif_bei -c "CREATE EXTENSION IF NOT EXISTS postgis_raster"')

if (nrow(dbGetQuery(con_bei, "SELECT 1 test WHERE to_regclass('canopee2019') IS NOT NULL;")) == 0) {
  system("raster2pgsql -s 32188 -I -C -M data/canopy/2019/*.tif -F -t 1000x1000 canopee2019 | psql -d gentrif_bei", intern = TRUE)
} else { message("PG Raster 'canopee2019' already imported") }
## PG Raster 'canopee2019' already imported
if (nrow(dbGetQuery(con_bei, "SELECT 1 test WHERE to_regclass('canopee2017') IS NOT NULL;")) == 0) {
  system("raster2pgsql -s 32188 -I -C -M data/canopy/2017/*.tif -F -t 1000x1000 canopee2017 | psql -d gentrif_bei", intern = TRUE)
} else { message("PG Raster 'canopee2017' already imported") }
## PG Raster 'canopee2017' already imported
if (nrow(dbGetQuery(con_bei, "SELECT 1 test WHERE to_regclass('canopee2015') IS NOT NULL;")) == 0) {
  system("raster2pgsql -s 32188 -I -C -M data/canopy/2015/*.tif -F -t 1000x1000 canopee2015 | psql -d gentrif_bei", intern = TRUE)
} else { message("PG Raster 'canopee2015' already imported") }
## PG Raster 'canopee2015' already imported
if (nrow(dbGetQuery(con_bei, "SELECT 1 test WHERE to_regclass('canopee2011') IS NOT NULL;")) == 0) {
  system("raster2pgsql -s 32188 -I -C -M data/canopy/2011/*.tif -F -t 1000x1000 canopee2011 | psql -d gentrif_bei", intern = TRUE)
} else { message("PG Raster 'canopee2011' already imported") }
## PG Raster 'canopee2011' already imported
# Resample to 10m as the original rasters have a 1m resolution, which is too high to allow for a swift processing
if (nrow(dbGetQuery(con_bei, "SELECT 1 test WHERE to_regclass('canopee2019_10m') IS NOT NULL;")) == 0) {
  system("gdal_translate -of GTiff PG:\"host=localhost dbname=gentrif_bei table=canopee2019 mode=2\" -r mode -tr 10 10 data/canopy/canopee2019_10m.tif")
  system("raster2pgsql -s 32188 -I -C -M data/canopy/canopee2019_10m.tif -F -t 100x100 canopee2019_10m | psql -d gentrif_bei")
} else { message("PG Raster 'canopee2019_10m' already imported") }
## PG Raster 'canopee2019_10m' already imported
if (nrow(dbGetQuery(con_bei, "SELECT 1 test WHERE to_regclass('canopee2017_10m') IS NOT NULL;")) == 0) {
  system("gdal_translate -of GTiff PG:\"host=localhost dbname=gentrif_bei table=canopee2017 mode=2\" -r mode -tr 10 10 data/canopy/canopee2017_10m.tif")
  system("raster2pgsql -s 32188 -I -C -M data/canopy/canopee2017_10m.tif -F -t 100x100 canopee2017_10m | psql -d gentrif_bei")
} else { message("PG Raster 'canopee2017_10m' already imported") }
## PG Raster 'canopee2017_10m' already imported
if (nrow(dbGetQuery(con_bei, "SELECT 1 test WHERE to_regclass('canopee2015_10m') IS NOT NULL;")) == 0) {
  system("gdal_translate -of GTiff PG:\"host=localhost dbname=gentrif_bei table=canopee2015 mode=2\" -r mode -tr 10 10 data/canopy/canopee2015_10m.tif")
  system("raster2pgsql -s 32188 -I -C -M data/canopy/canopee2015_10m.tif -F -t 100x100 canopee2015_10m | psql -d gentrif_bei")
} else { message("PG Raster 'canopee2015_10m' already imported") }
## PG Raster 'canopee2015_10m' already imported
if (nrow(dbGetQuery(con_bei, "SELECT 1 test WHERE to_regclass('canopee2011_10m') IS NOT NULL;")) == 0) {
  system("gdal_translate -of GTiff PG:\"host=localhost dbname=gentrif_bei table=canopee2011 mode=2\" -r mode -tr 10 10 data/canopy/canopee2011_10m.tif")
  system("raster2pgsql -s 32188 -I -C -M data/canopy/canopee2011_10m.tif -F -t 100x100 canopee2011_10m | psql -d gentrif_bei")
} else { message("PG Raster 'canopee2011_10m' already imported") }
## PG Raster 'canopee2011_10m' already imported
# Push CT16 to pg
if (nrow(dbGetQuery(con_bei, "SELECT 1 test WHERE to_regclass('ct16') IS NOT NULL;")) == 0) {
  CT16 %>%
    st_transform(crs = 32188) %>%
    st_write(con_bei, "ct16",
             layer_options = c("OVERWRITE=yes", "LAUNDER=true", "SPATIAL_INDEX=gist", "GEOMETRY_NAME=geom"))
  system("psql -d gentrif_bei -c 'CREATE INDEX ON  ct16 USING gist (geometry)'")
} else { message("PG Layer CT16 already imported") }
## PG Layer CT16 already imported
WITH cnt19 AS (
    SELECT "GeoUID", "Population"
        ,(pvc).value, SUM((pvc).count) As total
    FROM (SELECT "GeoUID", "Population"
            ,ST_ValueCount(ST_Clip(rast, geometry)) As pvc
        FROM canopee2019_10m
        JOIN ct16 ON ST_Intersects(geometry, rast)
    ) As foo
    GROUP BY "GeoUID", "Population", (pvc).value
),
canopee19 AS (
    SELECT "GeoUID"
        ,round(.1*.1 * sum(total) FILTER (WHERE value in (3, 4))) AS area_esp_vert_2019 -- area expressed in hectares
        ,round(100. * sum(total) FILTER (WHERE value in (3, 4)) / sum(total), 2) AS pct_esp_vert_2019
        ,round(.1*.1 * sum(total) FILTER (WHERE value = 4)) AS area_esp_vert_high_2019
        ,round(100. * sum(total) FILTER (WHERE value = 4) / sum(total), 2) AS pct_esp_vert_high_2019
    FROM cnt19
    WHERE value > 0 -- discard no data, including postgis raster no data
    GROUP BY "GeoUID", "Population"
),
cnt17 AS (
    SELECT "GeoUID", "Population"
        ,(pvc).value, SUM((pvc).count) As total
    FROM (SELECT "GeoUID", "Population"
            ,ST_ValueCount(ST_Clip(rast, geometry)) As pvc
        FROM canopee2017_10m
        JOIN ct16 ON ST_Intersects(geometry, rast)
    ) As foo
    GROUP BY "GeoUID", "Population", (pvc).value
),
canopee17 AS (
    SELECT "GeoUID"
        ,round(.1*.1 * sum(total) FILTER (WHERE value in (3, 4))) AS area_esp_vert_2017
        ,round(100. * sum(total) FILTER (WHERE value in (3, 4)) / sum(total), 2) AS pct_esp_vert_2017
        ,round(.1*.1 * sum(total) FILTER (WHERE value = 4)) AS area_esp_vert_high_2017
        ,round(100. * sum(total) FILTER (WHERE value = 4) / sum(total), 2) AS pct_esp_vert_high_2017
    FROM cnt17
    WHERE value > 0 -- discard no data, including postgis raster no data
    GROUP BY "GeoUID", "Population"
),
cnt15 AS (
    SELECT "GeoUID", "Population"
        ,(pvc).value, SUM((pvc).count) As total
    FROM (SELECT "GeoUID", "Population"
            ,ST_ValueCount(ST_Clip(rast, geometry)) As pvc
        FROM canopee2015_10m
        JOIN ct16 ON ST_Intersects(geometry, rast)
    ) As foo
    GROUP BY "GeoUID", "Population", (pvc).value
),
canopee15 AS (
    SELECT "GeoUID"
        ,round(.1*.1 * sum(total) FILTER (WHERE value in (3, 4))) AS area_esp_vert_2015
        ,round(100. * sum(total) FILTER (WHERE value in (3, 4)) / sum(total), 2) AS pct_esp_vert_2015
        ,round(.1*.1 * sum(total) FILTER (WHERE value = 4)) AS area_esp_vert_high_2015
        ,round(100. * sum(total) FILTER (WHERE value = 4) / sum(total), 2) AS pct_esp_vert_high_2015
    FROM cnt15
    WHERE value > 0 -- discard no data, including postgis raster no data
    GROUP BY "GeoUID", "Population"
),
cnt11 AS (
    SELECT "GeoUID", "Population"
        ,(pvc).value, SUM((pvc).count) As total
    FROM (SELECT "GeoUID", "Population"
            ,ST_ValueCount(ST_Clip(rast, geometry)) As pvc
        FROM canopee2011_10m
        JOIN ct16 ON ST_Intersects(geometry, rast)
    ) As foo
    GROUP BY "GeoUID", "Population", (pvc).value
),
canopee11 AS (
    SELECT "GeoUID"
        ,round(.1*.1 * sum(total) FILTER (WHERE value in (3, 4))) AS area_esp_vert_2011
        ,round(100. * sum(total) FILTER (WHERE value in (3, 4)) / sum(total), 2) AS pct_esp_vert_2011
        ,round(.1*.1 * sum(total) FILTER (WHERE value = 4)) AS area_esp_vert_high_2011
        ,round(100. * sum(total) FILTER (WHERE value = 4) / sum(total), 2) AS pct_esp_vert_high_2011
    FROM cnt11
    WHERE value > 0 -- discard no data, including postgis raster no data
    GROUP BY "GeoUID", "Population"
)
SELECT "GeoUID"
    ,round((st_area(geometry) / 10000)::numeric, 1) ct_area_h -- CT area in hectares
    ,COALESCE(area_esp_vert_2011, 0) area_esp_vert_2011
    ,coalesce(area_esp_vert_high_2011, 0) area_esp_vert_high_2011
    ,coalesce(pct_esp_vert_high_2011, 0) pct_esp_vert_high_2011
    ,coalesce(pct_esp_vert_2011, 0) pct_esp_vert_2011
    ,COALESCE(area_esp_vert_2015, 0) area_esp_vert_2015
    ,coalesce(area_esp_vert_high_2015, 0) area_esp_vert_high_2015
    ,coalesce(pct_esp_vert_high_2015, 0) pct_esp_vert_high_2015
    ,coalesce(pct_esp_vert_2015, 0) pct_esp_vert_2015
    ,COALESCE(area_esp_vert_2017, 0) area_esp_vert_2017
    ,coalesce(area_esp_vert_high_2017, 0) area_esp_vert_high_2017
    ,coalesce(pct_esp_vert_high_2017, 0) pct_esp_vert_high_2017
    ,coalesce(pct_esp_vert_2017, 0) pct_esp_vert_2017
    ,COALESCE(area_esp_vert_2019, 0) area_esp_vert_2019
    ,coalesce(area_esp_vert_high_2019, 0) area_esp_vert_high_2019
    ,coalesce(pct_esp_vert_high_2019, 0) pct_esp_vert_high_2019
    ,coalesce(pct_esp_vert_2019, 0) pct_esp_vert_2019
FROM ct16
FULL JOIN canopee19 USING ("GeoUID")
FULL JOIN canopee17 USING ("GeoUID")
FULL JOIN canopee15 USING ("GeoUID")
FULL JOIN canopee11 USING ("GeoUID");

2.3 Pampalon index

Get it here

pampalon <- read.xlsx("data/Canada2016Pampalon/A-MSDIData_Can2016_eng/1. EquivalenceTableCanada2016_ENG.xlsx", sheet = 2) %>%
  mutate(DA = as.character(DA)) %>%
  select(DA, SCOREMAT, SCORESOC)

# 2016 DA boundaries for Montreal
DA16 <- get_census(dataset='CA16', regions=list(CMA='24462'), level='DA', geo_format = "sf") %>%
  filter(Type == "DA") %>%
  st_transform(st_crs(bike_lane))
## Reading geo data from local cache.
pampalon <- DA16 %>%
  inner_join(pampalon, by = c("GeoUID" = "DA")) %>%
  as.data.frame()

# Get Pampalon 2006
pampalon06 <- read.xlsx("data/Canada2006Pampalon/A-MSDIData_Can2006_eng/1. CorrespondenceTable_Can2006_eng.xlsx", sheet = 2) %>%
  mutate(DA = as.character(DA)) %>%
  select(DA, DAPOP2006, SCOREMAT, SCORESOC)

# Get LUT DA2006 <-> DA2011 from StatCan
lut_da.1 <- read.csv("data/2011_92-156_DA_AD_txt/2011_92-156_DA_AD.txt", colClasses = "character", 
                     header = FALSE, col.names = c("DAUID2011.ADIDU2011", "DAUID2006.ADIDU2006", "DBUID2011", "DA_rel_flag")) %>%
  select(!c(DBUID2011, DA_rel_flag)) %>%
  unique()

# Link Pampalon 2011 to LUT and compute weighted mean of scores of Pampalon 2011
# NB: population numbers will diverge from  reality when more than one DA is merged into one DA of next census
pampalon06.11 <- pampalon06 %>%
  inner_join(lut_da.1, by = c("DA" = "DAUID2006.ADIDU2006")) %>%
  group_by(DAUID2011.ADIDU2011) %>%
  summarise(pop2006 = sum(DAPOP2006),
            SCOREMAT.06 = weighted.mean(SCOREMAT, DAPOP2006, na.rm = TRUE),
            SCORESOC.06 = weighted.mean(SCORESOC, DAPOP2006, na.rm = TRUE))

# Get Pampalon 2011
pampalon11 <- read.xlsx("data/Canada2011Pampalon/A-MSDIData_Can2011_eng/1. CorrespondenceTable_Can2011_eng.xlsx", sheet = 2) %>%
  mutate(DA = as.character(DA)) %>%
  select(DA, DAPOP2011, SCOREMAT, SCORESOC)

# Get LUT DA2011 <-> DA2016 from StatCan
lut_da <- read.csv("data/2016_92-156_DA_AD_csv/2016_92-156_DA_AD.csv", colClasses = "character") %>%
  select(!c(DBUID2016.IDIDU2016, DA_rel_flag.AD_ind_rel)) %>%
  unique()

# Link Pampalon 2011 to LUT, then to Pampalon 06 and finally compute weighted mean of scores of Pampalon 2011
pampalon11.16 <- pampalon11 %>%
  inner_join(lut_da, by = c("DA" = "DAUID2011.ADIDU2011")) %>%
  left_join(pampalon06.11, by =c("DA" = "DAUID2011.ADIDU2011")) %>%
  group_by(DAUID2016.ADIDU2016) %>%
  summarise(pop2011 = sum(DAPOP2011),
            SCOREMAT = weighted.mean(SCOREMAT, DAPOP2011, na.rm = TRUE),
            SCORESOC = weighted.mean(SCORESOC, DAPOP2011, na.rm = TRUE),
            SCOREMAT.06 = weighted.mean(SCOREMAT.06, pop2006, na.rm = TRUE),
            SCORESOC.06 = weighted.mean(SCORESOC.06, pop2006, na.rm = TRUE),
            pop2006 = sum(pop2006))

# Then link Pampalon 2011 to 2016
pampalon <- pampalon %>%
  left_join(pampalon11.16, by = c("GeoUID" = "DAUID2016.ADIDU2016"), suffix = c(".16", ".11"))

# Aggregate at the CT level
pampalon_CT <- pampalon %>%
  group_by(CT_UID) %>%
  summarise(wSCOREMAT.2016 = weighted.mean(SCOREMAT.16, Population, na.rm = TRUE),
            wSCORESOC.2016 = weighted.mean(SCORESOC.16, Population, na.rm = TRUE),
            wSCOREMAT.2011 = weighted.mean(SCOREMAT.11, pop2011, na.rm = TRUE),
            wSCORESOC.2011 = weighted.mean(SCORESOC.11, pop2011, na.rm = TRUE),
            wSCOREMAT.2006 = weighted.mean(SCOREMAT.06, pop2006, na.rm = TRUE),
            wSCORESOC.2006 = weighted.mean(SCORESOC.06, pop2006, na.rm = TRUE))

# Clean up
rm(lut_da, lut_da.1, pampalon11.16, pampalon06.11, pampalon11, pampalon06)

# Display map
.pampalon_CT_geom <- CT16 %>%
  left_join(pampalon_CT, by = c("GeoUID" = "CT_UID")) %>%
  filter(interact_aoi)

.pampalon_data <- bi_class(.pampalon_CT_geom, x = wSCOREMAT.2016, y = wSCORESOC.2016, style = "quantile", dim = 3)
## Warning in classInt::classIntervals(bins_x, n = dim, style = "quantile"): var
## has missing values, omitted in finding classes
## Warning in classInt::classIntervals(bins_y, n = dim, style = "quantile"): var
## has missing values, omitted in finding classes
.map <- ggplot() + 
  geom_sf(data = .pampalon_data, mapping = aes(fill = bi_class), color = "white", size = 0.1, show.legend = FALSE) +
  bi_scale_fill(pal = "DkBlue", dim = 3) +
  labs(title = "Pampalon: material and social deprivation index") + 
  theme(panel.background = element_rect(fill = "white"),
        #axis.ticks = element_blank(),
        #axis.text = element_blank(),
        panel.grid = element_line(color = "darkgray", size = 0.2))
.legend <- bi_legend(pal = "DkBlue",
                    dim = 3,
                    xlab = "Material ",
                    ylab = "Social ",
                    size = 8)
ggdraw() +
  draw_plot(.map, 0, 0, 1, 1) +
  draw_plot(.legend, 0.1, .7, 0.2, 0.2)

2.4 Gentrification

Using Ding metric computed on 5 year span.

# Load gentrified CTs, 5 year span (from repo gentrification_metrics)
ding <- list()
ding[["2016"]] <- st_read("data/gentrified_5years.gpkg", "gentrified_ding_16", quiet=TRUE) %>%
  filter(cma_uid_16 == "24462") %>%
  st_transform(st_crs(bike_lane))
ding[["2011"]] <- st_read("data/gentrified_5years.gpkg", "gentrified_ding_11", quiet=TRUE) %>%
  filter(cma_uid_11 == "24462") %>%
  st_transform(st_crs(bike_lane))
ding[["2006"]] <- st_read("data/gentrified_5years.gpkg", "gentrified_ding_06", quiet=TRUE) %>%
  filter(cma_uid_06 == "24462") %>%
  st_transform(st_crs(bike_lane))

.ding_map <- ding[["2016"]] %>%
  left_join(select(as.data.frame(CT16), GeoUID, interact_aoi), by = c("ct_uid_16" = "GeoUID")) %>%
  filter(interact_aoi)

ggplot(data = .ding_map) + 
  geom_sf(aes(fill = gentrified_2016_2011, colour=gentrifiable_2011)) +
  scale_fill_manual(values = c("gray", "red", "darkgray"), name = "Gentrified in 2016") +
  scale_colour_manual(values = c("darkgray", "darkred", "darkgray"), name = "Gentrifiable in 2011") +
  labs(title = "Census tract gentrification status in 2016")

2.5 Equity metrics | low-income population and visible minority

Introduced here as a proposition, nothing acted (2022-02-04)

# Visible Minority
# - v_CA16_3954: Total - Visible minority for the population in private households - 25% sample data (Total)
# - v_CA16_3957: Total visible minority population (Total)

# Low income (LIM-AT)
# - v_CA16_2540: Prevalence of low income based on the Low-income measure, after tax (LIM-AT) (%) (Total)
equity_ct16 <- get_census(dataset='CA16', regions=list(CMA='24462'), level='CT', geo_format = "sf",
                          vectors = c("v_CA16_3954", "v_CA16_3957", "v_CA16_2540")) %>%
  filter(Type == "CT") %>%
  transmute(CT_UID = GeoUID,
            vis_minority_2016 = `v_CA16_3957: Total visible minority population` / `v_CA16_3954: Total - Visible minority for the population in private households - 25% sample data` * 100,
            low_income_2016 = `v_CA16_2540: Prevalence of low income based on the Low-income measure, after tax (LIM-AT) (%)`)
## Reading vectors data from local cache.
## Reading geo data from local cache.
# Visible Minority
# - v_CA11N_457: CA 2011 NHS, Total population in private households by visible minority (Total)
# - v_CA11N_460: CA 2011 NHS, Total population in private households by visible minority, Total visible minority population (Total)

# Low income (LIM-AT)
# - v_CA11N_2606: CA 2011 NHS, Prevalence of low income in 2010 based on after-tax low-income measure % (Total)
equity_ct11 <- get_census(dataset='CA11', regions=list(CMA='24462'), level='CT', geo_format = "sf",
                          vectors = c("v_CA11N_457", "v_CA11N_460", "v_CA11N_2606")) %>%
  filter(Type == "CT") %>%
  transmute(CT_UID = GeoUID,
            vis_minority_2011 = `v_CA11N_460: Total visible minority population` / `v_CA11N_457: Total population in private households by visible minority` * 100,
            low_income_2011 = `v_CA11N_2606: Prevalence of low income in 2010 based on after-tax low-income measure %`)
## Reading vectors data from local cache.
## Reading geo data from local cache.
# Visible Minority
# - v_CA06_1302: Total population by visible minority groups
# - v_CA06_1303: Total population by visible minority groups, Total visible minority population

# Low income (LIM-AT)
# - v_TX2006_551: After-tax low income status of tax filers and dependents (census family low income measure, CFLIM-AT) for couple and lone parent families by family composition, 2006 | All family units | Persons in Low Income | % - Total
equity_ct06 <- get_census(dataset='CA06', regions=list(CMA='24462'), level='CT', geo_format = "sf",
                          vectors = c("v_CA06_1302", "v_CA06_1303", "v_TX2006_551")) %>%
  filter(Type == "CT") %>%
  transmute(CT_UID = GeoUID,
            vis_minority_2006 = `v_CA06_1303: Total visible minority population` / `v_CA06_1302: Total population by visible minority groups - 20% sample data` * 100,
            low_income_2006 = `v_TX2006_551: % - Total`)
## Reading vectors data from local cache.
## Reading geo data from local cache.
equity_ct <- st_join(equity_ct16, equity_ct11, left=TRUE, largest=TRUE, suffix=c("", "_2011")) %>% # join on largest overlap, to overcome mismatch in CT UID
  st_join(equity_ct06, left=TRUE, largest=TRUE, suffix=c("", "_2006")) %>%
  data.frame()
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries

## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
# cleanup
rm(equity_ct11, equity_ct16, equity_ct06)

# Display map
.equity_CT_geom <- CT16 %>%
  left_join(equity_ct, by = c("GeoUID" = "CT_UID")) %>%
  filter(interact_aoi)

.equity_data <- bi_class(.equity_CT_geom, x = vis_minority_2016, y = low_income_2016, style = "quantile", dim = 3)
## Warning in classInt::classIntervals(bins_x, n = dim, style = "quantile"): var
## has missing values, omitted in finding classes
## Warning in classInt::classIntervals(bins_y, n = dim, style = "quantile"): var
## has missing values, omitted in finding classes
.map <- ggplot() + 
  geom_sf(data = .equity_data, mapping = aes(fill = bi_class), color = "white", size = 0.1, show.legend = FALSE) +
  bi_scale_fill(pal = "Brown", dim = 3) +
  labs(title = "Equity metrics: % of visible minority and % of low-income household") + 
  theme(panel.background = element_rect(fill = "white"),
        #axis.ticks = element_blank(),
        #axis.text = element_blank(),
        panel.grid = element_line(color = "darkgray", size = 0.2))
.legend <- bi_legend(pal = "Brown",
                    dim = 3,
                    xlab = "Vis. Minority ",
                    ylab = "Low-Income ",
                    size = 8)
ggdraw() +
  draw_plot(.map, 0, 0, 1, 1) +
  draw_plot(.legend, 0.1, .7, 0.2, 0.2)

2.6 Build complete dataset

All variables + outcome linked at the CT level + quintiles of SES variables

.bike_lane_changes <- bike_lane_changes %>%
  as.data.frame() %>%
  select(GeoUID, starts_with("street_length"), ends_with("ct", ignore.case = FALSE)) %>%
  select(GeoUID, starts_with("street_length"), starts_with("Bike_lane")) # Drop individual category lane length

bei_df <- CT16 %>%
  as.data.frame() %>%
  transmute(CT_UID = GeoUID,
            CD_UID = CD_UID,
            CSD_UID = CSD_UID,
            interact_aoi = interact_aoi,
            Population = Population) %>%
  left_join(pampalon_CT, by="CT_UID") %>%
  left_join(select(as.data.frame(ding$`2016`), ct_uid_16, starts_with("gentrif")), by=c("CT_UID" = "ct_uid_16")) %>%
  left_join(select(as.data.frame(ding$`2011`), ct_uid_11, starts_with("gentrif")), by=c("CT_UID" = "ct_uid_11")) %>%
  left_join(select(as.data.frame(ding$`2006`), ct_uid_06, starts_with("gentrif")), by=c("CT_UID" = "ct_uid_06")) %>%
  left_join(select(as.data.frame(equity_ct), !c("geometry", "CT_UID_2011", "CT_UID_2006")), by="CT_UID") %>%
  left_join(.bike_lane_changes, by=c("CT_UID" = "GeoUID")) %>%
  left_join(as.data.frame(rename_with(esp_vert_ct, ~ paste0(., "ct"))), by=c("CT_UID" = "GeoUIDct")) %>%
  # Compute quintile of SES variables
  mutate(wSCOREMAT.2006.Q = ntile(wSCOREMAT.2006, 5),
         wSCOREMAT.2011.Q = ntile(wSCOREMAT.2011, 5),
         wSCOREMAT.2016.Q = ntile(wSCOREMAT.2016, 5),
         low_income_2006.Q = ntile(low_income_2006, 5),
         low_income_2011.Q = ntile(low_income_2011, 5),
         low_income_2016.Q = ntile(low_income_2016, 5),
         vis_minority_2006.Q = ntile(vis_minority_2006, 5),
         vis_minority_2011.Q = ntile(vis_minority_2011, 5),
         vis_minority_2016.Q = ntile(vis_minority_2016, 5)) %>%
  units::drop_units()
  
  
head(bei_df)
write.csv(bei_df, "data/_results/bei_equity.csv", na="", row.names = FALSE)

# keep only interact CT
bei_df_aoi <- filter(bei_df, interact_aoi)

Included variables:

  • Census Tracts variables
    • CT_UID: 2016 Census Tract ID
    • CD_UID: 2016 Census Division
    • CSD_UID: 2016 Census Subdivision
    • interact_aoi: Does CT belong to INTERACT study area?
    • Population: 2016 Population within CT
    • ct_area_m2ct: Area of CT, in square meters
  • Gentrification metrics
    • gentrified_2016_2011: Is the CT gentrified in 2016?
    • gentrifiable_2011: Is the CT candidate to gentrification in 2011?
    • gentrified_2011_2006: Is the CT gentrified in 2011
    • gentrifiable_2006: Is the CT candidate to gentrification in 2006
    • gentrified_2006_2001: Is the CT gentrified in 2006
    • gentrifiable_2001: Is the CT candidate to gentrification in 2001
  • Pampalon’s metrics
    • wSCORESOC.2016: Social deprivation index in 2016 (population weighted)
    • wSCOREMAT.2016: Material deprivation index in 2016 (population weighted)
    • wSCOREMAT.2016.Q: Quintile of material deprivation index in 2016 (population weighted)
    • wSCORESOC.2011: Social deprivation index in 2011 (population weighted)
    • wSCOREMAT.2011: Material deprivation index in 2011 (population weighted)
    • wSCOREMAT.2011.Q: Quintile of aterial deprivation index in 2011 (population weighted)
    • wSCORESOC.2006: Social deprivation index in 2006 (population weighted)
    • wSCOREMAT.2006: Material deprivation index in 2006 (population weighted)
    • wSCOREMAT.2006.Q: Quintile of material deprivation index in 2006 (population weighted)
  • Social profile
    • vis_minority_2016: % of visible minority in CT 2016
    • vis_minority_2016.Q: Quintile of % of visible minority in CT 2016
    • low_income_2016: prevalence of low income in CT 2016
    • low_income_2016.Q: Quintile of prevalence of low income in CT 2016
    • vis_minority_2011: % of visible minority in CT 2011
    • vis_minority_2011.Q: Quintile of % of visible minority in CT 2011
    • low_income_2011: prevalence of low income in CT 2011
    • low_income_2011.Q: Quintile of prevalence of low income in CT 2011
    • vis_minority_2006: % of visible minority in CT 2006
    • vis_minority_2006.Q: Quintile of % of visible minority in CT 2006
    • low_income_2006: prevalence of low income in CT 2006
    • low_income_2006.Q: Qintile of prevalence of low income in CT 2006
  • Bike lane density
    • Bike_lane_total.{2016|2011}ct: total length of bike lanes, in 2016 or 2011, within CT
    • Bike_lane_total.hm.{2016|2011}ct: total length of bike lanes, in hectometers (as integers), in 2016 or 2011, within CT
    • Bike_lane.by.street.{2016|2011}ct: % of bike lanes compared to streets, in 2016 or 2011, within CT
    • Bike_lane_diff.2011.2016ct: change in total length of bike lanes between 2011 and 2016, within CT
    • Bike_lane_diff.by.street.2011.2016ct: change in total length of bike lanes between 2011 and 2011, normalized by street length, within CT
    • Bike_lane_diff.by.area.2011.2016ct: change in total length of bike lanes between 2011 and 2011, normalized by area, within CT
  • Green spaces
    • area_esp_vert_{2011|2015|2019}ct: area of green space in 2011, 2015 or 2019 within CT (in hectares)
    • area_esp_vert_high_{2011|2015|2019}ct: same as above, except for trees (high canopy)
    • pct_esp_vert_{2011|2015|2019}ct: % of green space in 2011, 2015 or 2019 within CT
    • pct_esp_vert_high_{2011|2015|2019}ct: same as above, except for trees (high canopy)
    • pct_esp_vert_diff{2011|2015}.{2015|2019}ct: change in % of green space between 2011 and 2015, 2011 and 2019 as well as 2011 and 2019, within CT

3 Preliminary analyses

INTERACT study area ~ Montréal, Laval, Longueuil, Brossard, St-Lambert

3.1 SES variable distribution

.bei_df_long <- bei_df_aoi %>% 
  select(CT_UID, CD_UID, starts_with("wSCORE")) %>%
  select(!ends_with('.Q')) %>%
  pivot_longer(!c(CT_UID, CD_UID))

ggplot(.bei_df_long, aes(value)) +
  geom_histogram() + 
  facet_wrap(~name) #, scales = "free")
## Warning: Removed 86 rows containing non-finite values (stat_bin).

.bei_df_long <- bei_df_aoi %>%
  select(CT_UID, CD_UID, starts_with("vis_minority"), starts_with("low_income")) %>%
  select(!ends_with('.Q')) %>%
  pivot_longer(!c(CT_UID, CD_UID))

ggplot(.bei_df_long, aes(value)) +
  geom_histogram() + 
  facet_wrap(~name) #, scales = "free")
## Warning: Removed 85 rows containing non-finite values (stat_bin).

.bei_df_long <- bei_df_aoi %>%
  select(CT_UID, CD_UID, starts_with("gentrif")) %>%
  select(!ends_with('.Q')) %>%
  pivot_longer(!c(CT_UID, CD_UID))

ggplot(.bei_df_long, aes(value)) +
  geom_bar() + 
  facet_wrap(~name) #, scales = "free", ncol = 3)

3.2 BEI variable distributions

3.2.1 Absolute values

.bei_df_long <- bei_df_aoi %>% 
  filter(interact_aoi) %>%
  select(CT_UID, CD_UID, matches("^Bike_lane_total.*ct$"), matches("^area_esp_vert.*ct$")) %>%
  pivot_longer(!c(CT_UID, CD_UID))

ggplot(.bei_df_long, aes(value)) +
  geom_histogram() + 
  facet_wrap(~name, scales = "free", ncol = 4)

3.2.2 Relative values

.bei_df_long <- bei_df_aoi %>% 
  filter(interact_aoi) %>%
  select(CT_UID, CD_UID, matches("^Bike_lane.by.*ct$"), matches("^pct_esp_vert.*ct$")) %>%
  pivot_longer(!c(CT_UID, CD_UID))

ggplot(.bei_df_long, aes(value)) +
  geom_histogram() + 
  facet_wrap(~name, scales = "free", ncol = 3)

4 Association between SES and Urban Conditions at baseline (2011)

Looking at objective #1: do urban interventions tend to be located in low SES neighborhoods?. We look at \[Urban Condition_{2011} = f(SES_{2011})\] as well as \[Urban Condition_{2011} = f(Gentrification_{2011 \to 2016})\]

Here \(UrbanCondition\) means the state of the urban environment features, such as length of bike lanes, greenness coverage, etc. at one specific moment. This needs to be distinguished from \(UrbanIntervention\), which accounts for the changes in the \(UrbanConditions\) between two years (see below).

We fit LMM models, with spatial random effect using spaMM package.

4.1 UC vs Pampalon | material

Using a Poisson distribution.

4.1.1 Bike lane length

4.1.1.1 Model 1: bike lane ratio to streets (in %) at the Census tract level.

Original approach: wrongly specified.

f <- Bike_lane.by.street.2011ct ~ wSCOREMAT.2011.Q

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

res.lmm <- fitme(I(as.integer(Bike_lane.by.street.2011ct)) ~ wSCOREMAT.2011.Q + adjacency(1|ct_no),
                 data = clean_bei$df, adjMatrix = clean_bei$nbmatx, 
                 family = Poisson())
summary(res.lmm, details = c(p_value="Wald"))
## formula: I(as.integer(Bike_lane.by.street.2011ct)) ~ wSCOREMAT.2011.Q + 
##     adjacency(1 | ct_no)
## Estimation of corrPars and lambda by Laplace ML approximation (p_v).
## Estimation of fixed effects by Laplace ML approximation (p_v).
## Estimation of lambda by 'outer' ML, maximizing p_v.
## family: poisson( link = log ) 
##  ------------ Fixed effects (beta) ------------
##                  Estimate Cond. SE t-value  p-value
## (Intercept)        1.9981  0.21183   9.432 0.000000
## wSCOREMAT.2011.Q  -0.1554  0.05413  -2.870 0.004101
##  --------------- Random effects ---------------
## Family: gaussian( link = identity ) 
##                    --- Correlation parameters:
##     1.rho 
## 0.1367899 
##            --- Variance parameters ('lambda'):
## lambda = var(u) for u ~ Gaussian; 
##    ct_no  :  2.119  
## # of obs: 688; # of groups: ct_no, 688 
##  ------------- Likelihood values  -------------
##                         logLik
## p_v(h) (marginal L): -2165.674
ci.lmm <- confint(res.lmm, 'wSCOREMAT.2011.Q')
## lower wSCOREMAT.2011.Q upper wSCOREMAT.2011.Q 
##            -0.26338924            -0.04851102
simout <- simulateResiduals(fittedModel = res.lmm, plot = F)
plot(simout)

Interpretation of the wSCOREMAT.2011.Q coefficient (significant): we have \(e^{-0.155}\) = 0.856 (95%CI: 0.768 – 0.953), which means each increase of 1 quintile in the Material Score leads to a 14.4% decrease in the ratio of bike lanes to street.

4.1.1.2 Model 2: bike lane ratio to streets at the Census tract level, with offset.

As explained in Anderson’s presentation.

f <- Bike_lane_total.hm.2016ct ~ wSCOREMAT.2011.Q + offset(log(street_length.hm))

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

res.lmm.a <- fitme(Bike_lane_total.hm.2016ct ~ wSCOREMAT.2011.Q + offset(log(street_length.hm)) + adjacency(1|ct_no),
                 data = clean_bei$df, adjMatrix = clean_bei$nbmatx,
                 family = poisson())
summary(res.lmm.a, details = c(p_value="Wald"))
## formula: Bike_lane_total.hm.2016ct ~ wSCOREMAT.2011.Q + offset(log(street_length.hm)) + 
##     adjacency(1 | ct_no)
## Estimation of corrPars and lambda by Laplace ML approximation (p_v).
## Estimation of fixed effects by Laplace ML approximation (p_v).
## Estimation of lambda by 'outer' ML, maximizing p_v.
## family: poisson( link = log ) 
##  ------------ Fixed effects (beta) ------------
##                  Estimate Cond. SE t-value  p-value
## (Intercept)       -2.0383  0.13217 -15.422 0.000000
## wSCOREMAT.2011.Q  -0.1047  0.03381  -3.097 0.001954
##  --------------- Random effects ---------------
## Family: gaussian( link = identity ) 
##                    --- Correlation parameters:
##     1.rho 
## 0.1354287 
##            --- Variance parameters ('lambda'):
## lambda = var(u) for u ~ Gaussian; 
##    ct_no  :  0.8504  
## # of obs: 688; # of groups: ct_no, 688 
##  ------------- Likelihood values  -------------
##                         logLik
## p_v(h) (marginal L): -2504.243
ci.lmm.a <- confint(res.lmm.a, 'wSCOREMAT.2011.Q')
## lower wSCOREMAT.2011.Q upper wSCOREMAT.2011.Q 
##            -0.17152947            -0.03821378
simout <- simulateResiduals(fittedModel = res.lmm.a, plot = F)
plot(simout)

Interpretation of the wSCOREMAT.2011.Q coefficient (significant): we have \(e^{-0.105}\) = 0.901 (95%CI: 0.842 – 0.963), which means each increase of 1 quintile in the Material Score leads to a 9.9% decrease in the ratio of bike lanes to street.

4.1.1.3 Model 3: bike lane ratio to streets at the Census tract level, with offset and negative binomial distribution.

To better account for overdispersion. See papers by Roback as well as Gardner.

f <- Bike_lane_total.hm.2016ct ~ wSCOREMAT.2011.Q + offset(log(street_length.hm))

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

res.lmm.b <- fitme(Bike_lane_total.hm.2016ct ~ wSCOREMAT.2011.Q + offset(log(street_length.hm)) + adjacency(1|ct_no),
                 data = clean_bei$df, adjMatrix = clean_bei$nbmatx,
                 family = negbin())
summary(res.lmm.b, details = c(p_value="Wald"))
## formula: Bike_lane_total.hm.2016ct ~ wSCOREMAT.2011.Q + offset(log(street_length.hm)) + 
##     adjacency(1 | ct_no)
## Estimation of corrPars, lambda and NB_shape by Laplace ML approximation (p_v).
## Estimation of fixed effects by Laplace ML approximation (p_v).
## Estimation of lambda and NB_shape by 'outer' ML, maximizing p_v.
## family: Neg.binomial(shape=1.064)( link = log ) 
##  ------------ Fixed effects (beta) ------------
##                  Estimate Cond. SE t-value  p-value
## (Intercept)      -1.94556  0.09313 -20.891 0.000000
## wSCOREMAT.2011.Q -0.07327  0.02637  -2.779 0.005454
##  --------------- Random effects ---------------
## Family: gaussian( link = identity ) 
##                    --- Correlation parameters:
##     1.rho 
## 0.1385164 
##            --- Variance parameters ('lambda'):
## lambda = var(u) for u ~ Gaussian; 
##    ct_no  :  2.998e-05  
## # of obs: 688; # of groups: ct_no, 688 
##  ------------- Likelihood values  -------------
##                         logLik
## p_v(h) (marginal L): -2471.752
ci.lmm.b <- confint(res.lmm.b, 'wSCOREMAT.2011.Q')
## lower wSCOREMAT.2011.Q upper wSCOREMAT.2011.Q 
##            -0.12694873            -0.02031836
simout <- simulateResiduals(fittedModel = res.lmm.b, plot = F)
plot(simout)

Interpretation of the wSCOREMAT.2011.Q coefficient (significant): we have \(e^{-0.073}\) = 0.929 (95%CI: 0.881 – 0.98), which means each increase of 1 quintile in the Material Score leads to a 7.1% decrease in the ratio of bike lanes to street.

4.1.2 Canopy

4.1.2.1 Model 0: orginal one, with raw ratio (no offset) and Gaussian distribution

Measuring canopy (i.e. greenness ~ grass & trees) ratio within CT/buffer in 2011 (in %) at the Census tract level, using a Poisson distribution

f <- pct_esp_vert_2011ct ~ wSCOREMAT.2011.Q

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

res.lmm <- fitme(pct_esp_vert_2011ct ~ wSCOREMAT.2011.Q + adjacency(1|ct_no),
                 data = clean_bei$df, adjMatrix = clean_bei$nbmatx)
summary(res.lmm, details = c(p_value="Wald"))
## formula: pct_esp_vert_2011ct ~ wSCOREMAT.2011.Q + adjacency(1 | ct_no)
## ML: Estimation of corrPars, lambda and phi by ML.
##     Estimation of fixed effects by ML.
## Estimation of lambda and phi by 'outer' ML, maximizing p_v.
## family: gaussian( link = identity ) 
##  ------------ Fixed effects (beta) ------------
##                  Estimate Cond. SE t-value   p-value
## (Intercept)        50.157   1.4712  34.093 0.000e+00
## wSCOREMAT.2011.Q   -2.782   0.3624  -7.676 1.643e-14
##  --------------- Random effects ---------------
## Family: gaussian( link = identity ) 
##                    --- Correlation parameters:
##     1.rho 
## 0.1382906 
##            --- Variance parameters ('lambda'):
## lambda = var(u) for u ~ Gaussian; 
##    ct_no  :  114.5  
## # of obs: 688; # of groups: ct_no, 688 
##  -------------- Residual variance  ------------
## phi estimate was 0.00024413 
##  ------------- Likelihood values  -------------
##                         logLik
## p_v(h) (marginal L): -2641.862
#ci.lmm <- confint(res.lmm, 'wSCOREMAT.2011.Q')

simout <- simulateResiduals(fittedModel = res.lmm, plot = F)
plot(simout)

4.1.2.2 Model 1: orginal one, with raw ratio (no offset) and Poisson distribution

Measuring canopy (i.e. greenness ~ grass & trees) ratio within CT/buffer in 2011 (in %) at the Census tract level, using a Poisson distribution

f <- pct_esp_vert_2011ct ~ wSCOREMAT.2011.Q

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

res.lmm <- fitme(I(as.integer(pct_esp_vert_2011ct)) ~ wSCOREMAT.2011.Q + adjacency(1|ct_no),
                 data = clean_bei$df, adjMatrix = clean_bei$nbmatx, 
                 family = Poisson())
summary(res.lmm, details = c(p_value="Wald"))
## formula: I(as.integer(pct_esp_vert_2011ct)) ~ wSCOREMAT.2011.Q + adjacency(1 | 
##     ct_no)
## Estimation of corrPars and lambda by Laplace ML approximation (p_v).
## Estimation of fixed effects by Laplace ML approximation (p_v).
## Estimation of lambda by 'outer' ML, maximizing p_v.
## family: poisson( link = log ) 
##  ------------ Fixed effects (beta) ------------
##                  Estimate Cond. SE t-value   p-value
## (Intercept)       3.88360  0.04083  95.111 0.000e+00
## wSCOREMAT.2011.Q -0.07603  0.01038  -7.327 2.347e-13
##  --------------- Random effects ---------------
## Family: gaussian( link = identity ) 
##                    --- Correlation parameters:
##     1.rho 
## 0.1383775 
##            --- Variance parameters ('lambda'):
## lambda = var(u) for u ~ Gaussian; 
##    ct_no  :  0.06782  
## # of obs: 688; # of groups: ct_no, 688 
##  ------------- Likelihood values  -------------
##                         logLik
## p_v(h) (marginal L): -2632.299
ci.lmm <- confint(res.lmm, 'wSCOREMAT.2011.Q')
## lower wSCOREMAT.2011.Q upper wSCOREMAT.2011.Q 
##            -0.09639313            -0.05560739
simout <- simulateResiduals(fittedModel = res.lmm, plot = F)
plot(simout)

Interpretation of the wSCOREMAT.2011.Q coefficient (significant): we have \(e^{-0.076}\) = 0.927 (95%CI: 0.908 – 0.946), which means each increase of 1 quintile in the Material Score leads to a 7.3% decrease in the percentage of greenspace.

4.1.2.3 Model 2: with ratio specifed via offset and Poisson distribution

f <- area_esp_vert_2011ct ~ wSCOREMAT.2011.Q + offset(log(ct_area_hct))

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

res.lmm <- fitme(area_esp_vert_2011ct ~ wSCOREMAT.2011.Q + offset(log(ct_area_hct)) + adjacency(1|ct_no),
                 data = clean_bei$df, adjMatrix = clean_bei$nbmatx, 
                 family = Poisson())
summary(res.lmm, details = c(p_value="Wald"))
## formula: area_esp_vert_2011ct ~ wSCOREMAT.2011.Q + offset(log(ct_area_hct)) + 
##     adjacency(1 | ct_no)
## Estimation of corrPars and lambda by Laplace ML approximation (p_v).
## Estimation of fixed effects by Laplace ML approximation (p_v).
## Estimation of lambda by 'outer' ML, maximizing p_v.
## family: poisson( link = log ) 
##  ------------ Fixed effects (beta) ------------
##                  Estimate Cond. SE t-value   p-value
## (Intercept)      -0.62343  0.03922 -15.895 0.000e+00
## wSCOREMAT.2011.Q -0.08301  0.01029  -8.065 7.772e-16
##  --------------- Random effects ---------------
## Family: gaussian( link = identity ) 
##                    --- Correlation parameters:
##     1.rho 
## 0.1383759 
##            --- Variance parameters ('lambda'):
## lambda = var(u) for u ~ Gaussian; 
##    ct_no  :  0.0557  
## # of obs: 688; # of groups: ct_no, 688 
##  ------------- Likelihood values  -------------
##                         logLik
## p_v(h) (marginal L): -2413.744
ci.lmm <- confint(res.lmm, 'wSCOREMAT.2011.Q')
## lower wSCOREMAT.2011.Q upper wSCOREMAT.2011.Q 
##            -0.10320178            -0.06275188
simout <- simulateResiduals(fittedModel = res.lmm, plot = F)
plot(simout)

Interpretation of the wSCOREMAT.2011.Q coefficient (significant): we have \(e^{-0.083}\) = 0.92 (95%CI: 0.902 – 0.939), which means each increase of 1 quintile in the Material Score leads to a 8% decrease in the percentage of greenspace.

4.1.2.4 Model 3: with ratio specifed via offset and Negative binomial distribution

Seems to be similar to Poisson, yet fit is not Ok (unable to compute CI)

f <- area_esp_vert_2011ct ~ wSCOREMAT.2011.Q + offset(log(ct_area_hct))

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

res.lmm <- fitme(area_esp_vert_2011ct ~ wSCOREMAT.2011.Q + offset(log(ct_area_hct)) + adjacency(1|ct_no),
                 data = clean_bei$df, adjMatrix = clean_bei$nbmatx, 
                 family = negbin())
summary(res.lmm, details = c(p_value="Wald"))
## formula: area_esp_vert_2011ct ~ wSCOREMAT.2011.Q + offset(log(ct_area_hct)) + 
##     adjacency(1 | ct_no)
## Estimation of corrPars, lambda and NB_shape by Laplace ML approximation (p_v).
## Estimation of fixed effects by Laplace ML approximation (p_v).
## Estimation of lambda and NB_shape by 'outer' ML, maximizing p_v.
## family: Neg.binomial(shape=816000)( link = log ) 
##  ------------ Fixed effects (beta) ------------
##                  Estimate Cond. SE t-value   p-value
## (Intercept)      -0.62344  0.03922 -15.895 0.000e+00
## wSCOREMAT.2011.Q -0.08301  0.01029  -8.065 7.772e-16
##  --------------- Random effects ---------------
## Family: gaussian( link = identity ) 
##                    --- Correlation parameters:
##     1.rho 
## 0.1383752 
##            --- Variance parameters ('lambda'):
## lambda = var(u) for u ~ Gaussian; 
##    ct_no  :  0.0557  
## # of obs: 688; # of groups: ct_no, 688 
##  ------------- Likelihood values  -------------
##                         logLik
## p_v(h) (marginal L): -2413.745
#ci.lmm <- confint(res.lmm, 'wSCOREMAT.2011.Q')

simout <- simulateResiduals(fittedModel = res.lmm, plot = F)
plot(simout)

Interpretation of the wSCOREMAT.2011.Q coefficient (significant): we have \(e^{-0.083}\) = 0.92, which means each increase of 1 quintile in the Material Score leads to a 8% decrease in the percentage of greenspace.

4.1.3 Canopy (trees)

Measuring high canopy (i.e. trees only) ratio within CT/buffer in 2011 (in %) at the Census tract level, using a Poisson distribution

f <- pct_esp_vert_high_2011ct ~ wSCOREMAT.2011.Q

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

res.lmm <- fitme(I(as.integer(pct_esp_vert_high_2011ct)) ~ wSCOREMAT.2011.Q + adjacency(1|ct_no),
                 data = clean_bei$df, adjMatrix = clean_bei$nbmatx, 
                 family = Poisson())
summary(res.lmm, details = c(p_value="Wald"))
## formula: I(as.integer(pct_esp_vert_high_2011ct)) ~ wSCOREMAT.2011.Q + 
##     adjacency(1 | ct_no)
## Estimation of corrPars and lambda by Laplace ML approximation (p_v).
## Estimation of fixed effects by Laplace ML approximation (p_v).
## Estimation of lambda by 'outer' ML, maximizing p_v.
## family: poisson( link = log ) 
##  ------------ Fixed effects (beta) ------------
##                  Estimate Cond. SE t-value  p-value
## (Intercept)        3.2306  0.05420  59.608 0.00e+00
## wSCOREMAT.2011.Q  -0.1147  0.01395  -8.224 2.22e-16
##  --------------- Random effects ---------------
## Family: gaussian( link = identity ) 
##                    --- Correlation parameters:
##     1.rho 
## 0.1378436 
##            --- Variance parameters ('lambda'):
## lambda = var(u) for u ~ Gaussian; 
##    ct_no  :  0.1159  
## # of obs: 688; # of groups: ct_no, 688 
##  ------------- Likelihood values  -------------
##                         logLik
## p_v(h) (marginal L): -2319.833
ci.lmm <- confint(res.lmm, 'wSCOREMAT.2011.Q')
## lower wSCOREMAT.2011.Q upper wSCOREMAT.2011.Q 
##            -0.14208172            -0.08721304

Interpretation of the wSCOREMAT.2011.Q coefficient (significant): we have \(e^{-0.115}\) = 0.892 (95%CI: 0.868 – 0.916), which means each increase of 1 quintile in the Material Score leads to a 10.8% decrease in the percentage of tree canopy.

4.2 UC vs Visible minority

4.2.1 Bike lane length

Bike lane ratio to streets (in %) at the Census tract level

f <- Bike_lane.by.street.2011ct ~ vis_minority_2011.Q

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

res.lmm <- fitme(I(as.integer(Bike_lane.by.street.2011ct)) ~ vis_minority_2011.Q + adjacency(1|ct_no),
                 data = clean_bei$df, adjMatrix = clean_bei$nbmatx, 
                 family = Poisson())
summary(res.lmm, details = c(p_value="Wald"))
## formula: I(as.integer(Bike_lane.by.street.2011ct)) ~ vis_minority_2011.Q + 
##     adjacency(1 | ct_no)
## Estimation of corrPars and lambda by Laplace ML approximation (p_v).
## Estimation of fixed effects by Laplace ML approximation (p_v).
## Estimation of lambda by 'outer' ML, maximizing p_v.
## family: poisson( link = log ) 
##  ------------ Fixed effects (beta) ------------
##                     Estimate Cond. SE t-value   p-value
## (Intercept)           1.9839  0.26918   7.370 1.706e-13
## vis_minority_2011.Q  -0.1434  0.06995  -2.051 4.029e-02
##  --------------- Random effects ---------------
## Family: gaussian( link = identity ) 
##                    --- Correlation parameters:
##     1.rho 
## 0.1363317 
##            --- Variance parameters ('lambda'):
## lambda = var(u) for u ~ Gaussian; 
##    ct_no  :  2.127  
## # of obs: 688; # of groups: ct_no, 688 
##  ------------- Likelihood values  -------------
##                         logLik
## p_v(h) (marginal L): -2164.609
ci.lmm <- confint(res.lmm, "vis_minority_2011.Q")
## lower vis_minority_2011.Q upper vis_minority_2011.Q 
##              -0.282985691              -0.004421956

Interpretation of the vis_minority_2011.Q coefficient (significant): we have \(e^{-0.143}\) = 0.866 (95%CI: 0.754 – 0.996), which means each increase of 1 quintile in the Material Score leads to a 13.4% decrease in the ratio of bike lanes to street.

4.2.2 Canopy

Measuring canopy (i.e. greenness ~ grass & trees) ratio within CT/buffer in 2011 (in %) at the Census tract level

f <- pct_esp_vert_2011ct ~ vis_minority_2011.Q

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

res.lmm <- fitme(I(as.integer(pct_esp_vert_2011ct)) ~ vis_minority_2011.Q + adjacency(1|ct_no),
                 data = clean_bei$df, adjMatrix = clean_bei$nbmatx, 
                 family = Poisson())
summary(res.lmm, details = c(p_value="Wald"))
## formula: I(as.integer(pct_esp_vert_2011ct)) ~ vis_minority_2011.Q + adjacency(1 | 
##     ct_no)
## Estimation of corrPars and lambda by Laplace ML approximation (p_v).
## Estimation of fixed effects by Laplace ML approximation (p_v).
## Estimation of lambda by 'outer' ML, maximizing p_v.
## family: poisson( link = log ) 
##  ------------ Fixed effects (beta) ------------
##                     Estimate Cond. SE t-value   p-value
## (Intercept)          3.92812  0.05231  75.100 0.000e+00
## vis_minority_2011.Q -0.08179  0.01353  -6.045 1.493e-09
##  --------------- Random effects ---------------
## Family: gaussian( link = identity ) 
##                    --- Correlation parameters:
##     1.rho 
## 0.1385831 
##            --- Variance parameters ('lambda'):
## lambda = var(u) for u ~ Gaussian; 
##    ct_no  :  0.0693  
## # of obs: 688; # of groups: ct_no, 688 
##  ------------- Likelihood values  -------------
##                         logLik
## p_v(h) (marginal L): -2631.974
ci.lmm <- confint(res.lmm, 'vis_minority_2011.Q')
## lower vis_minority_2011.Q upper vis_minority_2011.Q 
##               -0.10835435               -0.05518919

Interpretation of the vis_minority_2011.Q coefficient (significant): we have \(e^{-0.082}\) = 0.921 (95%CI: 0.897 – 0.946), which means each increase of 1 quintile in the Material Score leads to a 7.9% decrease in the percentage of greenspace.

4.2.3 Canopy (trees)

Measuring high canopy (i.e. trees only) ratio within CT/buffer in 2011 (in %) at the Census tract level

f <- pct_esp_vert_high_2011ct ~ vis_minority_2011.Q

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

res.lmm <- fitme(I(as.integer(pct_esp_vert_high_2011ct)) ~ vis_minority_2011.Q + adjacency(1|ct_no),
                 data = clean_bei$df, adjMatrix = clean_bei$nbmatx, 
                 family = Poisson())
summary(res.lmm, details = c(p_value="Wald"))
## formula: I(as.integer(pct_esp_vert_high_2011ct)) ~ vis_minority_2011.Q + 
##     adjacency(1 | ct_no)
## Estimation of corrPars and lambda by Laplace ML approximation (p_v).
## Estimation of fixed effects by Laplace ML approximation (p_v).
## Estimation of lambda by 'outer' ML, maximizing p_v.
## family: poisson( link = log ) 
##  ------------ Fixed effects (beta) ------------
##                     Estimate Cond. SE t-value   p-value
## (Intercept)           3.3237  0.07012  47.398 0.000e+00
## vis_minority_2011.Q  -0.1329  0.01826  -7.282 3.287e-13
##  --------------- Random effects ---------------
## Family: gaussian( link = identity ) 
##                    --- Correlation parameters:
##     1.rho 
## 0.1381433 
##            --- Variance parameters ('lambda'):
## lambda = var(u) for u ~ Gaussian; 
##    ct_no  :  0.1209  
## # of obs: 688; # of groups: ct_no, 688 
##  ------------- Likelihood values  -------------
##                         logLik
## p_v(h) (marginal L): -2322.004
ci.lmm <- confint(res.lmm, 'vis_minority_2011.Q')
## lower vis_minority_2011.Q upper vis_minority_2011.Q 
##               -0.16886457               -0.09707289

Interpretation of the vis_minority_2011.Q coefficient (significant): we have \(e^{-0.133}\) = 0.876 (95%CI: 0.845 – 0.907), which means each increase of 1 quintile in the Material Score leads to a 12.4% decrease in the percentage of tree canopy.

4.3 UC vs gentrified CT

Gentrified CT between 2011 and 2016

4.3.1 Bike lane length

Bike lane ratio to streets (in %) at the Census tract level

f <- Bike_lane.by.street.2011ct ~ gentrified_2016_2011

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

res.lmm <- fitme(I(as.integer(Bike_lane.by.street.2011ct)) ~ gentrified_2016_2011 + adjacency(1|ct_no),
                 data = clean_bei$df, adjMatrix = clean_bei$nbmatx, 
                 family = Poisson())
summary(res.lmm, details = c(p_value="Wald"))
## formula: I(as.integer(Bike_lane.by.street.2011ct)) ~ gentrified_2016_2011 + 
##     adjacency(1 | ct_no)
## Estimation of corrPars and lambda by Laplace ML approximation (p_v).
## Estimation of fixed effects by Laplace ML approximation (p_v).
## Estimation of lambda by 'outer' ML, maximizing p_v.
## family: poisson( link = log ) 
##  ------------ Fixed effects (beta) ------------
##                          Estimate Cond. SE t-value p-value
## (Intercept)                1.5323   0.1373 11.1637  0.0000
## gentrified_2016_2011TRUE  -0.1037   0.1528 -0.6787  0.4973
##  --------------- Random effects ---------------
## Family: gaussian( link = identity ) 
##                    --- Correlation parameters:
##     1.rho 
## 0.1368245 
##            --- Variance parameters ('lambda'):
## lambda = var(u) for u ~ Gaussian; 
##    ct_no  :  2.143  
## # of obs: 688; # of groups: ct_no, 688 
##  ------------- Likelihood values  -------------
##                         logLik
## p_v(h) (marginal L): -2166.427
ci.lmm <- confint(res.lmm, 'gentrified_2016_2011TRUE')
## lower gentrified_2016_2011TRUE upper gentrified_2016_2011TRUE 
##                     -0.4081798                      0.1991900

Interpretation of the gentrified_2016_2011 coefficient (not significant): we have \(e^{-0.104}\) = 0.902 (95%CI: 0.665 – 1.22)

4.3.2 Canopy

Measuring canopy (i.e. greenness ~ grass & trees) ratio within CT/buffer in 2011 (in %) at the Census tract level

f <- pct_esp_vert_2011ct ~ gentrified_2016_2011

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

res.lmm <- fitme(I(as.integer(pct_esp_vert_2011ct)) ~ gentrified_2016_2011 + adjacency(1|ct_no),
                 data = clean_bei$df, adjMatrix = clean_bei$nbmatx, 
                 family = Poisson())
summary(res.lmm, details = c(p_value="Wald"))
## formula: I(as.integer(pct_esp_vert_2011ct)) ~ gentrified_2016_2011 + adjacency(1 | 
##     ct_no)
## Estimation of corrPars and lambda by Laplace ML approximation (p_v).
## Estimation of fixed effects by Laplace ML approximation (p_v).
## Estimation of lambda by 'outer' ML, maximizing p_v.
## family: poisson( link = log ) 
##  ------------ Fixed effects (beta) ------------
##                          Estimate Cond. SE t-value   p-value
## (Intercept)                3.7022  0.02657 139.347 0.000e+00
## gentrified_2016_2011TRUE  -0.1867  0.03005  -6.212 5.243e-10
##  --------------- Random effects ---------------
## Family: gaussian( link = identity ) 
##                    --- Correlation parameters:
##     1.rho 
## 0.1385693 
##            --- Variance parameters ('lambda'):
## lambda = var(u) for u ~ Gaussian; 
##    ct_no  :  0.06904  
## # of obs: 688; # of groups: ct_no, 688 
##  ------------- Likelihood values  -------------
##                         logLik
## p_v(h) (marginal L): -2630.999
ci.lmm <- confint(res.lmm, 'gentrified_2016_2011TRUE')
## lower gentrified_2016_2011TRUE upper gentrified_2016_2011TRUE 
##                     -0.2456846                     -0.1275226

Interpretation of the gentrified_2016_2011 coefficient (not significant): we have \(e^{-0.187}\) = 0.83 (95%CI: 0.782 – 0.88), which means gentrified CTs exhibit a 17% decrease in the percentage of greenspace.

4.3.3 Canopy (trees)

Measuring high canopy (i.e. trees only) ratio within CT/buffer in 2011 (in %) at the Census tract level

f <- pct_esp_vert_high_2011ct ~ gentrified_2016_2011

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

res.lmm <- fitme(I(as.integer(pct_esp_vert_high_2011ct)) ~ gentrified_2016_2011 + adjacency(1|ct_no),
                 data = clean_bei$df, adjMatrix = clean_bei$nbmatx, 
                 family = Poisson())
summary(res.lmm, details = c(p_value="Wald"))
## formula: I(as.integer(pct_esp_vert_high_2011ct)) ~ gentrified_2016_2011 + 
##     adjacency(1 | ct_no)
## Estimation of corrPars and lambda by Laplace ML approximation (p_v).
## Estimation of fixed effects by Laplace ML approximation (p_v).
## Estimation of lambda by 'outer' ML, maximizing p_v.
## family: poisson( link = log ) 
##  ------------ Fixed effects (beta) ------------
##                          Estimate Cond. SE t-value   p-value
## (Intercept)                2.9117  0.03688   78.96 0.0000000
## gentrified_2016_2011TRUE  -0.1378  0.04150   -3.32 0.0008986
##  --------------- Random effects ---------------
## Family: gaussian( link = identity ) 
##                    --- Correlation parameters:
##     1.rho 
## 0.1381482 
##            --- Variance parameters ('lambda'):
## lambda = var(u) for u ~ Gaussian; 
##    ct_no  :  0.1312  
## # of obs: 688; # of groups: ct_no, 688 
##  ------------- Likelihood values  -------------
##                         logLik
## p_v(h) (marginal L): -2341.985
ci.lmm <- confint(res.lmm, 'gentrified_2016_2011TRUE')
## lower gentrified_2016_2011TRUE upper gentrified_2016_2011TRUE 
##                    -0.21939468                    -0.05612476

Interpretation of the gentrified_2016_2011 coefficient (not significant): we have \(e^{-0.138}\) = 0.871 (95%CI: 0.803 – 0.945), which means gentrified CTs exhibit a 12.9% decrease in the percentage of tree canopy

5 Association between SES and Urban Interventions at baseline (2011)

Looking at objective #1 | do urban interventions tend to be located in low SES neighborhoods?. We look at \[Urban Intervention_{2011 \to 2016} = f(SES_{2011})\] as well as \[Urban Intervention_{2011 \to 2016} = f(Gentrification_{2011 \to 2016})\]

Here \(Urban Intervention\) means the changes in the urban environment features, such as variation of bike lane length, greenness coverage, etc.

5.1 UI vs Pampalon | material

Using Gaussian distribution || TODO: need to confirm

5.1.1 Bike lane length change

5.1.1.1 Model 1: Bike lane ratio to streets (in %) at the Census tract level

f <- Bike_lane_diff.by.street.2011.2016ct ~ wSCOREMAT.2011.Q + Bike_lane.by.street.2011ct

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

res.lmm <- fitme(Bike_lane_diff.by.street.2011.2016ct ~ wSCOREMAT.2011.Q + Bike_lane.by.street.2011ct + adjacency(1|ct_no),
                 data = clean_bei$df, adjMatrix = clean_bei$nbmatx)
summary(res.lmm, details = c(p_value="Wald"))
## formula: Bike_lane_diff.by.street.2011.2016ct ~ wSCOREMAT.2011.Q + Bike_lane.by.street.2011ct + 
##     adjacency(1 | ct_no)
## ML: Estimation of corrPars, lambda and phi by ML.
##     Estimation of fixed effects by ML.
## Estimation of lambda and phi by 'outer' ML, maximizing p_v.
## family: gaussian( link = identity ) 
##  ------------ Fixed effects (beta) ------------
##                            Estimate Cond. SE t-value   p-value
## (Intercept)                 3.78897  0.84089  4.5059 6.608e-06
## wSCOREMAT.2011.Q           -0.08441  0.19480 -0.4333 6.648e-01
## Bike_lane.by.street.2011ct -0.06108  0.02621 -2.3302 1.980e-02
##  --------------- Random effects ---------------
## Family: gaussian( link = identity ) 
##                    --- Correlation parameters:
##     1.rho 
## 0.1379346 
##            --- Variance parameters ('lambda'):
## lambda = var(u) for u ~ Gaussian; 
##    ct_no  :  25.18  
## # of obs: 688; # of groups: ct_no, 688 
##  -------------- Residual variance  ------------
## phi estimate was 8.91883 
##  ------------- Likelihood values  -------------
##                         logLik
## p_v(h) (marginal L): -2222.995
moran.test(residuals.HLfit(res.lmm), clean_bei$nbw, zero.policy = TRUE)
## 
##  Moran I test under randomisation
## 
## data:  residuals.HLfit(res.lmm)  
## weights: clean_bei$nbw    
## 
## Moran I statistic standard deviate = -4.5591, p-value = 1
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic       Expectation          Variance 
##     -0.1062174555     -0.0014556041      0.0005280274
# Plotting residuals and fitted values
test_resid <- CT16 %>%
  inner_join(clean_bei$df, by=c("GeoUID" = "CT_UID")) %>%
  mutate(fitted.values = res.lmm$fv,
         resid = residuals.HLfit(res.lmm))

gbl <- ggplot(test_resid) + geom_sf(aes(fill=Bike_lane_diff.by.street.2011.2016ct), lwd=.2) + scale_fill_gradient(low = "white", high = "blue",
                            limits = c(min(test_resid$Bike_lane_diff.by.street.2011.2016ct),max(test_resid$Bike_lane_diff.by.street.2011.2016ct)))
gfv <- ggplot(test_resid) + geom_sf(aes(fill=fitted.values), lwd=.2)+ scale_fill_gradient(low = "white", high = "blue",
                            limits = c(min(test_resid$Bike_lane_diff.by.street.2011.2016ct),max(test_resid$Bike_lane_diff.by.street.2011.2016ct)))
grd <- ggplot(test_resid) + geom_sf(aes(fill=resid), lwd=.2)+ scale_fill_gradient(low = "dark blue", high = "red")
cowplot::plot_grid(gbl + theme(legend.position="none", axis.ticks = element_blank(), axis.text = element_blank()),
                   gfv + theme(legend.position="none", axis.ticks = element_blank(), axis.text = element_blank()),
                   grd + theme(legend.position="none", axis.ticks = element_blank(), axis.text = element_blank()),
                   labels = c("Bike lanes", "Fitted values", "Residuals"))

# Residuals distrib
ggplot(test_resid) + geom_histogram(aes(resid))

# Bland-Altman
ggplot(test_resid) + geom_point(aes(x=(fitted.values + Bike_lane_diff.by.street.2011.2016ct)/2, y=fitted.values - Bike_lane_diff.by.street.2011.2016ct))

# DHARMa test
simulationOutput <- simulateResiduals(fittedModel = res.lmm, plot = F)
plot(simulationOutput)

testZeroInflation(simulationOutput)

## 
##  DHARMa zero-inflation test via comparison to expected zeros with
##  simulation under H0 = fitted model
## 
## data:  simulationOutput
## ratioObsSim = Inf, p-value < 2.2e-16
## alternative hypothesis: two.sided

5.1.1.2 Model 2: Bike lane length change, modeled as pre-post change

As suggested in Jones’s answer, change is better modeled through \[UC_{2016} = \beta_{0} + \beta_{1} * UC_{2011} + \beta_{2} * SES\]

Bike lane ratio to streets (in %) at the Census tract level

f <- Bike_lane.by.street.2016ct ~ wSCOREMAT.2011.Q + Bike_lane.by.street.2011ct

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

res.lmm.2 <- fitme(I(as.integer(Bike_lane.by.street.2016ct)) ~ wSCOREMAT.2011.Q + Bike_lane.by.street.2011ct + adjacency(1|ct_no),
                 data = clean_bei$df, adjMatrix = clean_bei$nbmatx,
                 family = Poisson())
summary(res.lmm.2, details = c(p_value="Wald"))
## formula: I(as.integer(Bike_lane.by.street.2016ct)) ~ wSCOREMAT.2011.Q + 
##     Bike_lane.by.street.2011ct + adjacency(1 | ct_no)
## Estimation of corrPars and lambda by Laplace ML approximation (p_v).
## Estimation of fixed effects by Laplace ML approximation (p_v).
## Estimation of lambda by 'outer' ML, maximizing p_v.
## family: poisson( link = log ) 
##  ------------ Fixed effects (beta) ------------
##                            Estimate Cond. SE t-value p-value
## (Intercept)                 1.36538 0.111603  12.234  0.0000
## wSCOREMAT.2011.Q           -0.02941 0.025957  -1.133  0.2572
## Bike_lane.by.street.2011ct  0.08268 0.003388  24.401  0.0000
##  --------------- Random effects ---------------
## Family: gaussian( link = identity ) 
##                    --- Correlation parameters:
##     1.rho 
## 0.1370116 
##            --- Variance parameters ('lambda'):
## lambda = var(u) for u ~ Gaussian; 
##    ct_no  :  0.4476  
## # of obs: 688; # of groups: ct_no, 688 
##  ------------- Likelihood values  -------------
##                         logLik
## p_v(h) (marginal L): -2249.525
moran.test(residuals.HLfit(res.lmm.2), clean_bei$nbw, zero.policy = TRUE)
## 
##  Moran I test under randomisation
## 
## data:  residuals.HLfit(res.lmm.2)  
## weights: clean_bei$nbw    
## 
## Moran I statistic standard deviate = 2.6048, p-value = 0.004596
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic       Expectation          Variance 
##      0.0586530449     -0.0014556041      0.0005325063
# Plotting residuals and fitted values
test_resid <- CT16 %>%
  inner_join(clean_bei$df, by=c("GeoUID" = "CT_UID")) %>%
  mutate(fitted.values = res.lmm.2$fv,
         resid = residuals.HLfit(res.lmm.2))

gbl <- ggplot(test_resid) + geom_sf(aes(fill=Bike_lane.by.street.2016ct), lwd=.2) + scale_fill_gradient(low = "white", high = "blue",
                            limits = c(min(test_resid$Bike_lane.by.street.2016ct),max(test_resid$Bike_lane.by.street.2016ct)))
gfv <- ggplot(test_resid) + geom_sf(aes(fill=fitted.values), lwd=.2)+ scale_fill_gradient(low = "white", high = "blue",
                            limits = c(min(test_resid$Bike_lane.by.street.2016ct),max(test_resid$Bike_lane.by.street.2016ct)))
grd <- ggplot(test_resid) + geom_sf(aes(fill=resid), lwd=.2)+ scale_fill_gradient(low = "dark blue", high = "red")
cowplot::plot_grid(gbl + theme(legend.position="none", axis.ticks = element_blank(), axis.text = element_blank()),
                   gfv + theme(legend.position="none", axis.ticks = element_blank(), axis.text = element_blank()),
                   grd + theme(legend.position="none", axis.ticks = element_blank(), axis.text = element_blank()),
                   labels = c("Bike lanes", "Fitted values", "Residuals"))

# Residuals distrib
ggplot(test_resid) + geom_histogram(aes(resid))

# Bland-Altman
ggplot(test_resid) + geom_point(aes(x=(fitted.values + Bike_lane.by.street.2016ct)/2, y=fitted.values - Bike_lane.by.street.2016ct))

# DHARMa test
simulationOutput <- simulateResiduals(fittedModel = res.lmm.2, plot = F)
plot(simulationOutput)

testZeroInflation(simulationOutput)

## 
##  DHARMa zero-inflation test via comparison to expected zeros with
##  simulation under H0 = fitted model
## 
## data:  simulationOutput
## ratioObsSim = 4.3296, p-value < 2.2e-16
## alternative hypothesis: two.sided

5.1.1.3 Model 3: same as model 2, this time with OFFSET

See paper here for an explanation about this offset term in formula. We model the UI as a UC in 2016 explained by UC 2011 (same as Jones, see above) but this time rate \(bike_lane / streets\) is decomposed to have the street length on the RHS with a natural log. We also use hectometer, in order to find a good balance between the need for integers (as required by the Poisson distribution) and the precision.

First model with Bike_lane_total.2011ct independent variable.

f <- Bike_lane_total.hm.2016ct ~ wSCOREMAT.2011.Q + Bike_lane_total.2011ct + offset(street_length.hm)

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

res.lmm.3 <- fitme(Bike_lane_total.hm.2016ct ~ wSCOREMAT.2011.Q + Bike_lane_total.2011ct + offset(log(street_length.hm)) + adjacency(1|ct_no),
                 data = clean_bei$df, adjMatrix = clean_bei$nbmatx,
                 family = poisson())
summary(res.lmm.3, details = c(p_value="Wald"))
## formula: Bike_lane_total.hm.2016ct ~ wSCOREMAT.2011.Q + Bike_lane_total.2011ct + 
##     offset(log(street_length.hm)) + adjacency(1 | ct_no)
## Estimation of corrPars and lambda by Laplace ML approximation (p_v).
## Estimation of fixed effects by Laplace ML approximation (p_v).
## Estimation of lambda by 'outer' ML, maximizing p_v.
## family: poisson( link = log ) 
##  ------------ Fixed effects (beta) ------------
##                          Estimate  Cond. SE  t-value p-value
## (Intercept)            -2.5792405 1.285e-01 -20.0794  0.0000
## wSCOREMAT.2011.Q       -0.0248314 3.097e-02  -0.8019  0.4226
## Bike_lane_total.2011ct  0.0001737 1.534e-05  11.3243  0.0000
##  --------------- Random effects ---------------
## Family: gaussian( link = identity ) 
##                    --- Correlation parameters:
##     1.rho 
## 0.1363628 
##            --- Variance parameters ('lambda'):
## lambda = var(u) for u ~ Gaussian; 
##    ct_no  :  0.6547  
## # of obs: 688; # of groups: ct_no, 688 
##  ------------- Likelihood values  -------------
##                         logLik
## p_v(h) (marginal L): -2445.517
confint(res.lmm.3, "wSCOREMAT.2011.Q")
## lower wSCOREMAT.2011.Q upper wSCOREMAT.2011.Q 
##            -0.08593598             0.03611265
confint(res.lmm.3, "Bike_lane_total.2011ct")
## lower Bike_lane_total.2011ct upper Bike_lane_total.2011ct 
##                 0.0001435516                 0.0002044979
moran.test(residuals.HLfit(res.lmm.3), clean_bei$nbw, zero.policy = TRUE)
## 
##  Moran I test under randomisation
## 
## data:  residuals.HLfit(res.lmm.3)  
## weights: clean_bei$nbw    
## 
## Moran I statistic standard deviate = 3.3135, p-value = 0.0004606
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic       Expectation          Variance 
##      0.0749888086     -0.0014556041      0.0005322449
# Plotting residuals and fitted values
test_resid <- CT16 %>%
  inner_join(clean_bei$df, by=c("GeoUID" = "CT_UID")) %>%
  mutate(fitted.values = res.lmm.3$fv,
         resid = residuals.HLfit(res.lmm.3))

# Residuals distrib
ggplot(test_resid) + geom_histogram(aes(resid))

# Bland-Altman
ggplot(test_resid) + geom_point(aes(x=(fitted.values + Bike_lane_total.hm.2016ct)/2, y=fitted.values - Bike_lane_total.hm.2016ct))

# DHARMa test
simulationOutput <- simulateResiduals(fittedModel = res.lmm.3, plot = F)
plot(simulationOutput)

testZeroInflation(simulationOutput)

## 
##  DHARMa zero-inflation test via comparison to expected zeros with
##  simulation under H0 = fitted model
## 
## data:  simulationOutput
## ratioObsSim = 2.843, p-value < 2.2e-16
## alternative hypothesis: two.sided

Second model with Bike_lane.by.street.2011ct independent variable, which should be a better match for the Bike_lane_total.2016ct/ street_length rate.

f <- Bike_lane_total.hm.2016ct ~ wSCOREMAT.2011.Q + Bike_lane.by.street.2011ct + offset(street_length.hm)

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

res.lmm.3a <- fitme(Bike_lane_total.hm.2016ct ~ wSCOREMAT.2011.Q + Bike_lane.by.street.2011ct + offset(log(street_length.hm)) + adjacency(1|ct_no),
                 data = clean_bei$df, adjMatrix = clean_bei$nbmatx,
                 family = poisson())
summary(res.lmm.3a, details = c(p_value="Wald"))
## formula: Bike_lane_total.hm.2016ct ~ wSCOREMAT.2011.Q + Bike_lane.by.street.2011ct + 
##     offset(log(street_length.hm)) + adjacency(1 | ct_no)
## Estimation of corrPars and lambda by Laplace ML approximation (p_v).
## Estimation of fixed effects by Laplace ML approximation (p_v).
## Estimation of lambda by 'outer' ML, maximizing p_v.
## family: poisson( link = log ) 
##  ------------ Fixed effects (beta) ------------
##                            Estimate Cond. SE t-value p-value
## (Intercept)                -3.02949 0.094292 -32.129  0.0000
## wSCOREMAT.2011.Q           -0.03468 0.021826  -1.589  0.1121
## Bike_lane.by.street.2011ct  0.07478 0.002923  25.586  0.0000
##  --------------- Random effects ---------------
## Family: gaussian( link = identity ) 
##                    --- Correlation parameters:
##     1.rho 
## 0.1374017 
##            --- Variance parameters ('lambda'):
## lambda = var(u) for u ~ Gaussian; 
##    ct_no  :  0.293  
## # of obs: 688; # of groups: ct_no, 688 
##  ------------- Likelihood values  -------------
##                         logLik
## p_v(h) (marginal L): -2272.816
confint(res.lmm.3a, "wSCOREMAT.2011.Q")
## lower wSCOREMAT.2011.Q upper wSCOREMAT.2011.Q 
##           -0.077781824            0.008205798
confint(res.lmm.3a, "Bike_lane.by.street.2011ct")
## lower Bike_lane.by.street.2011ct upper Bike_lane.by.street.2011ct 
##                       0.06895637                       0.08083309
moran.test(residuals.HLfit(res.lmm.3a), clean_bei$nbw, zero.policy = TRUE)
## 
##  Moran I test under randomisation
## 
## data:  residuals.HLfit(res.lmm.3a)  
## weights: clean_bei$nbw    
## 
## Moran I statistic standard deviate = 3.1009, p-value = 0.0009647
## alternative hypothesis: greater
## sample estimates:
## Moran I statistic       Expectation          Variance 
##      0.0700795507     -0.0014556041      0.0005321862
# Plotting residuals and fitted values
test_resid <- CT16 %>%
  inner_join(clean_bei$df, by=c("GeoUID" = "CT_UID")) %>%
  mutate(fitted.values = res.lmm.3a$fv,
         resid = residuals.HLfit(res.lmm.3a))

# Residuals distrib
ggplot(test_resid) + geom_histogram(aes(resid))

# Bland-Altman
ggplot(test_resid) + geom_point(aes(x=(fitted.values + Bike_lane_total.hm.2016ct)/2, y=fitted.values - Bike_lane_total.hm.2016ct))

# DHARMa test
simulationOutput <- simulateResiduals(fittedModel = res.lmm.3a, plot = F)
plot(simulationOutput)

testZeroInflation(simulationOutput)

## 
##  DHARMa zero-inflation test via comparison to expected zeros with
##  simulation under H0 = fitted model
## 
## data:  simulationOutput
## ratioObsSim = 2.9062, p-value < 2.2e-16
## alternative hypothesis: two.sided

5.1.2 Canopy change

Measuring canopy (i.e. greenness ~ grass & trees) ratio within CT/buffer in 2011 (in %) at the Census tract level

f <- pct_esp_vert_diff_2011.2017ct ~ wSCOREMAT.2011 + pct_esp_vert_2011ct

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

ggplot(clean_bei$df, aes(y=pct_esp_vert_diff_2011.2017ct, x=wSCOREMAT.2011)) +
  geom_point() +
  geom_smooth(method=lm)

res.lm <- lm(pct_esp_vert_diff_2011.2017ct ~ wSCOREMAT.2011, data = units::drop_units(bei_df_aoi))
summary(res.lm)

# Accounting for UC in 2011
res.lm <- lm(f, data = clean_bei$df)
summary(res.lm)

# Check spatial autocorrelation of residuals
lm.morantest(res.lm, clean_bei$nbw)

# Test which spatial model?
lm.LMtests(res.lm, clean_bei$nbw, test="all")

# Get SAR and SEM models
fit.lag <- lagsarlm(formula = f, data = clean_bei$df, listw = clean_bei$nbw)
fit.err <- errorsarlm(formula = f, data = clean_bei$df, listw = clean_bei$nbw)

stargazer(res.lm, fit.lag, fit.err, type="text")

5.1.3 Canopy (trees) change

Measuring high canopy (i.e. trees only) ratio within CT/buffer in 2011 (in %) at the Census tract level

f <- pct_esp_vert_diff_high_2011.2017ct ~ wSCOREMAT.2011 + pct_esp_vert_high_2011ct

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

ggplot(clean_bei$df, aes(y=pct_esp_vert_diff_high_2011.2017ct, x=wSCOREMAT.2011)) +
  geom_point() +
  geom_smooth(method=lm)

res.lm <- lm(pct_esp_vert_diff_high_2011.2017ct ~ wSCOREMAT.2011, data = units::drop_units(bei_df_aoi))
summary(res.lm)

# Accounting for UC in 2011
res.lm <- lm(f, data = clean_bei$df)
summary(res.lm)

# Check spatial autocorrelation of residuals
lm.morantest(res.lm, clean_bei$nbw)

# Test which spatial model?
lm.LMtests(res.lm, clean_bei$nbw, test="all")

# Get SAR and SEM models
fit.lag <- lagsarlm(formula = f, data = clean_bei$df, listw = clean_bei$nbw)
fit.err <- errorsarlm(formula = f, data = clean_bei$df, listw = clean_bei$nbw)

stargazer(res.lm, fit.lag, fit.err, type="text")

5.2 UI vs Visible minority

5.2.1 Bike lane length change

Bike lane ratio to streets (in %). With or without controlling for UC in 2011 at the Census tract level

f <- Bike_lane_diff.by.street.2011.2016ct ~ vis_minority_2011 + Bike_lane.by.street.2011ct

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

ggplot(clean_bei$df, aes(y=Bike_lane_diff.by.street.2011.2016ct, x=vis_minority_2011)) +
  geom_point() +
  geom_smooth(method=lm)

res.lm <- lm(Bike_lane_diff.by.street.2011.2016ct ~ vis_minority_2011, data = units::drop_units(bei_df_aoi))
summary(res.lm)

# Accounting for UC in 2011
res.lm <- lm(f, data = clean_bei$df)
summary(res.lm)

# Check spatial autocorrelation of residuals
lm.morantest(res.lm, clean_bei$nbw)

# Test which spatial model?
lm.LMtests(res.lm, clean_bei$nbw, test="all")

# Get SAR and SEM models
fit.lag <- lagsarlm(formula = f, data = clean_bei$df, listw = clean_bei$nbw)
fit.err <- errorsarlm(formula = f, data = clean_bei$df, listw = clean_bei$nbw)

stargazer(res.lm, fit.lag, fit.err, type="text")

5.2.2 Canopy change

Measuring canopy (i.e. greenness ~ grass & trees) ratio within CT/buffer in 2011 (in %) at the Census tract level

f <- pct_esp_vert_diff_2011.2017ct ~ vis_minority_2011 + pct_esp_vert_2011ct

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

ggplot(clean_bei$df, aes(y=pct_esp_vert_diff_2011.2017ct, x=vis_minority_2011)) +
  geom_point() +
  geom_smooth(method=lm)

res.lm <- lm(pct_esp_vert_diff_2011.2017ct ~ vis_minority_2011, data = units::drop_units(bei_df_aoi))
summary(res.lm)

# Accounting for UC in 2011
res.lm <- lm(f, data = clean_bei$df)
summary(res.lm)

# Check spatial autocorrelation of residuals
lm.morantest(res.lm, clean_bei$nbw)

# Test which spatial model?
lm.LMtests(res.lm, clean_bei$nbw, test="all")

# Get SAR and SEM models
fit.lag <- lagsarlm(formula = f, data = clean_bei$df, listw = clean_bei$nbw)
fit.err <- errorsarlm(formula = f, data = clean_bei$df, listw = clean_bei$nbw)

stargazer(res.lm, fit.lag, fit.err, type="text")

5.2.3 Canopy (trees) change

Measuring high canopy (i.e. trees only) ratio within CT/buffer in 2011 (in %) at the Census tract level

f <- pct_esp_vert_diff_high_2011.2017ct ~ vis_minority_2011 + pct_esp_vert_high_2011ct

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

ggplot(clean_bei$df, aes(y=pct_esp_vert_diff_high_2011.2017ct, x=vis_minority_2011)) +
  geom_point() +
  geom_smooth(method=lm)

res.lm <- lm(pct_esp_vert_diff_high_2011.2017ct ~ vis_minority_2011, data = units::drop_units(bei_df_aoi))
summary(res.lm)

# Accounting for UC in 2011
res.lm <- lm(f, data = clean_bei$df)
summary(res.lm)

# Check spatial autocorrelation of residuals
lm.morantest(res.lm, clean_bei$nbw)

# Test which spatial model?
lm.LMtests(res.lm, clean_bei$nbw, test="all")

# Get SAR and SEM models
fit.lag <- lagsarlm(formula = f, data = clean_bei$df, listw = clean_bei$nbw)
fit.err <- errorsarlm(formula = f, data = clean_bei$df, listw = clean_bei$nbw)

stargazer(res.lm, fit.lag, fit.err, type="text")

5.3 UI vs gentrified CT

Gentrified CT between 2011 and 2016

5.3.1 Bike lane length change

Bike lane ratio to streets (in %) at the Census tract level

f <- Bike_lane_diff.by.street.2011.2016ct ~ gentrified_2016_2011 + Bike_lane.by.street.2011ct

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

ggplot(clean_bei$df, aes(y=Bike_lane_diff.by.street.2011.2016ct, x=gentrified_2016_2011)) +
  geom_boxplot()

clean_bei$df %>%
  group_by(gentrified_2016_2011) %>%
  summarise(
    count = n(),
    mean = mean(Bike_lane_diff.by.street.2011.2016ct, na.rm = TRUE),
    sd = sd(Bike_lane_diff.by.street.2011.2016ct, na.rm = TRUE)
  )

# Compute the analysis of variance
res.aov <- aov(Bike_lane_diff.by.street.2011.2016ct ~ gentrified_2016_2011, data = clean_bei$df)
# Summary of the analysis
summary(res.aov)

# Linear model
res.lm <- lm(Bike_lane_diff.by.street.2011.2016ct ~ gentrified_2016_2011, data = units::drop_units(bei_df_aoi))
summary(res.lm)

# Accounting for UC in 2011
res.lm <- lm(f, data = clean_bei$df)
summary(res.lm)

# Check spatial autocorrelation of residuals
lm.morantest(res.lm, clean_bei$nbw)

# Test which spatial model?
lm.LMtests(res.lm, clean_bei$nbw, test="all")

# Get SAR and SEM models
fit.lag <- lagsarlm(formula = f, data = clean_bei$df, listw = clean_bei$nbw)
fit.err <- errorsarlm(formula = f, data = clean_bei$df, listw = clean_bei$nbw)

stargazer(res.lm, fit.lag, fit.err, type="text")

5.3.2 Canopy change

Measuring canopy (i.e. greenness ~ grass & trees) ratio within CT/buffer in 2011 (in %) at the Census tract level

f <- pct_esp_vert_diff_2011.2017ct ~ gentrified_2016_2011 + pct_esp_vert_2011ct

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

ggplot(clean_bei$df, aes(y=pct_esp_vert_diff_2011.2017ct, x=gentrified_2016_2011)) +
  geom_boxplot()

clean_bei$df %>%
  group_by(gentrified_2016_2011) %>%
  summarise(
    count = n(),
    mean = mean(pct_esp_vert_diff_2011.2017ct, na.rm = TRUE),
    sd = sd(pct_esp_vert_diff_2011.2017ct, na.rm = TRUE)
  )

# Compute the analysis of variance
res.aov <- aov(pct_esp_vert_diff_2011.2017ct ~ gentrified_2016_2011, data = clean_bei$df)
# Summary of the analysis
summary(res.aov)

# Linear model
res.lm <- lm(pct_esp_vert_diff_2011.2017ct ~ gentrified_2016_2011, data = units::drop_units(bei_df_aoi))
summary(res.lm)

# Accounting for UC in 2011
res.lm <- lm(f, data = clean_bei$df)
summary(res.lm)

# Check spatial autocorrelation of residuals
lm.morantest(res.lm, clean_bei$nbw)

# Test which spatial model?
lm.LMtests(res.lm, clean_bei$nbw, test="all")

# Get SAR and SEM models
fit.lag <- lagsarlm(formula = f, data = clean_bei$df, listw = clean_bei$nbw)
fit.err <- errorsarlm(formula = f, data = clean_bei$df, listw = clean_bei$nbw)

stargazer(res.lm, fit.lag, fit.err, type="text")

5.3.3 Canopy (trees) change

Measuring high canopy (i.e. trees only) ratio within CT/buffer in 2011 (in %) at the Census tract level

f <- pct_esp_vert_diff_high_2011.2017ct ~ gentrified_2016_2011 + pct_esp_vert_high_2011ct

clean_bei <- tidy_df(bei_df_aoi, CT16, f)

ggplot(clean_bei$df, aes(y=pct_esp_vert_diff_high_2011.2017ct, x=gentrified_2016_2011)) +
  geom_boxplot()

clean_bei$df %>%
  group_by(gentrified_2016_2011) %>%
  summarise(
    count = n(),
    mean = mean(pct_esp_vert_diff_high_2011.2017ct, na.rm = TRUE),
    sd = sd(pct_esp_vert_diff_high_2011.2017ct, na.rm = TRUE)
  )

# Compute the analysis of variance
res.aov <- aov(pct_esp_vert_diff_high_2011.2017ct ~ gentrified_2016_2011, data = clean_bei$df)
# Summary of the analysis
summary(res.aov)

# Linear model
res.lm <- lm(pct_esp_vert_diff_high_2011.2017ct ~ gentrified_2016_2011, data = units::drop_units(bei_df_aoi))
summary(res.lm)

# Accounting for UC in 2011
res.lm <- lm(f, data = clean_bei$df)
summary(res.lm)

# Check spatial autocorrelation of residuals
lm.morantest(res.lm, clean_bei$nbw)

# Test which spatial model?
lm.LMtests(res.lm, clean_bei$nbw, test="all")

# Get SAR and SEM models
fit.lag <- lagsarlm(formula = f, data = clean_bei$df, listw = clean_bei$nbw)
fit.err <- errorsarlm(formula = f, data = clean_bei$df, listw = clean_bei$nbw)

stargazer(res.lm, fit.lag, fit.err, type="text")

6 Summary of association between SES and Built Environment

SES metric BE metric UC 2011 trend UI 2011 -> 2016 trend
Pampalon / MAT 2011 Bike lane 0.856 (0.768 – 0.953) x (-**‡ when controlling for UC)
Pampalon / MAT 2011 Greenness 0.927 (0.908 – 0.946) x (-*† when controlling for UC)
Pampalon / MAT 2011 Tree canopy 0.892 (0.868 – 0.916) -***†
Visible Minority 2011 Bike lane 0.866 (0.754 – 0.996) -***†
Visible Minority 2011 Greenness 0.921 (0.897 – 0.946) -* (-**† when controlling for UC)
Visible Minority 2011 Tree canopy 0.876 (0.845 – 0.907) -***†
Gentrified 2011-2016 Bike lane 0.902 (0.665 – 1.220) +***†
Gentrified 2011-2016 Greenness 0.830 (0.782 – 0.880) +** (x† when controlling for UC)
Gentrified 2011-2016 Tree canopy 0.871 (0.803 – 0.945) +***†

Controlling for UC in UI models does not change the association trend; even better, non significant association may become (slightly) significant.

7 Annexes

## R version 4.1.2 (2021-11-01)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Big Sur 10.16
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8
## 
## attached base packages:
## [1] parallel  stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] cancensus_0.5.0  DHARMa_0.4.5     INLA_21.11.22    foreach_1.5.2   
##  [5] stargazer_5.2.2  spaMM_3.10.0     cachem_1.0.6     memoise_2.0.1   
##  [9] spatialreg_1.2-1 spdep_1.2-2      spData_2.0.1     sp_1.4-6        
## [13] emmeans_1.7.2    sjPlot_2.8.10    lme4_1.1-28      Matrix_1.4-0    
## [17] biscale_0.2.0    openxlsx_4.2.5   RPostgres_1.4.3  DBI_1.1.2       
## [21] cowplot_1.1.1    ggmap_3.0.0      ggplot2_3.3.5    stars_0.5-5     
## [25] abind_1.4-5      sf_1.0-6         tidyr_1.2.0      dplyr_1.0.8     
## 
## loaded via a namespace (and not attached):
##   [1] backports_1.4.1     lwgeom_0.2-8        plyr_1.8.6         
##   [4] splines_4.1.2       digest_0.6.29       htmltools_0.5.2    
##   [7] gdata_2.18.0        fansi_1.0.2         magrittr_2.0.2     
##  [10] geojsonsf_2.0.1     doParallel_1.0.17   modelr_0.1.8       
##  [13] gmodels_2.18.1      jpeg_0.1-9          colorspace_2.0-3   
##  [16] blob_1.2.2          xfun_0.29           crayon_1.5.0       
##  [19] jsonlite_1.8.0      iterators_1.0.14    glue_1.6.2         
##  [22] registry_0.5-1      gtable_0.3.0        sjstats_0.18.1     
##  [25] sjmisc_2.8.9        scales_1.1.1        mvtnorm_1.1-3      
##  [28] ggeffects_1.1.1     Rcpp_1.0.8          xtable_1.8-4       
##  [31] performance_0.8.0   units_0.8-0         bit_4.0.4          
##  [34] proxy_0.4-26        datawizard_0.2.3    httr_1.4.2         
##  [37] RColorBrewer_1.1-2  wk_0.6.0            ellipsis_0.3.2     
##  [40] pkgconfig_2.0.3     farver_2.1.0        qgam_1.3.4         
##  [43] sass_0.4.0          deldir_1.0-6        utf8_1.2.2         
##  [46] later_1.3.0         tidyselect_1.1.2    labeling_0.4.2     
##  [49] rlang_1.0.1         effectsize_0.6.0.1  munsell_0.5.0      
##  [52] tools_4.1.2         cli_3.2.0           generics_0.1.2     
##  [55] sjlabelled_1.1.8    broom_0.7.12        evaluate_0.15      
##  [58] stringr_1.4.0       fastmap_1.1.0       yaml_2.3.5         
##  [61] knitr_1.37          bit64_4.0.5         zip_2.2.0          
##  [64] purrr_0.3.4         s2_1.0.7            RgoogleMaps_1.4.5.3
##  [67] pbapply_1.5-0       nlme_3.1-155        mime_0.12          
##  [70] slam_0.1-50         ROI_1.0-0           gap_1.2.3-1        
##  [73] compiler_4.1.2      rstudioapi_0.13     png_0.1-7          
##  [76] e1071_1.7-9         tibble_3.1.6        bslib_0.3.1        
##  [79] stringi_1.7.6       highr_0.9           parameters_0.16.0  
##  [82] lattice_0.20-45     classInt_0.4-3      nloptr_2.0.0       
##  [85] vctrs_0.3.8         pillar_1.7.0        LearnBayes_2.15.1  
##  [88] lifecycle_1.0.1     jquerylib_0.1.4     estimability_1.3   
##  [91] bitops_1.0-7        insight_0.16.0      raster_3.5-15      
##  [94] httpuv_1.6.5        R6_2.5.1            promises_1.2.0.1   
##  [97] KernSmooth_2.23-20  codetools_0.2-18    boot_1.3-28        
## [100] MASS_7.3-55         gtools_3.9.2        assertthat_0.2.1   
## [103] rjson_0.2.21        withr_2.4.3         mgcv_1.8-39        
## [106] bayestestR_0.11.5   expm_0.999-6        hms_1.1.1          
## [109] terra_1.5-21        grid_4.1.2          coda_0.19-4        
## [112] class_7.3-20        minqa_1.2.4         rmarkdown_2.11     
## [115] shiny_1.7.1         numDeriv_2016.8-1.1 lubridate_1.8.0